diff --git a/.gitignore b/.gitignore index e44636dc5bb..f85addaf207 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,7 @@ node_g # various stuff that VC++ produces/uses Debug/ Release/ +!doc/blog/** *.sln !nodemsi.sln *.suo @@ -39,6 +40,5 @@ ipch/ /npm.wxs /tools/msvs/npm.wixobj email.md -blog.html deps/v8-* -node_modules +./node_modules diff --git a/AUTHORS b/AUTHORS index 4aa563fbfa9..a389d07ce48 100644 --- a/AUTHORS +++ b/AUTHORS @@ -184,7 +184,7 @@ Yoshihiro KIKUCHI Brett Kiefer Mariano Iglesias Jörn Horstmann -Joe Shaw +Joe Shaw Alex Xu Kip Gebhardt Stefan Rusu @@ -314,3 +314,11 @@ Kevin Gadd Ray Solomon Kevin Bowman Jeroen Janssen +Matt Gollob +Simon Sturmer +Joel Brandt +Marc Harter +Nuno Job +Ben Kelly +Felix Böhm +Gabriel de Perthuis diff --git a/ChangeLog b/ChangeLog index b2ce37d586a..03a7fdca0bf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,185 @@ -2012.05.28, Version 0.7.9 (unstable) +2012.06.29, Version 0.8.1 (stable) + +* V8: upgrade to v3.11.10.12 + +* npm: upgrade to v1.1.33 + - Support for parallel use of the cache folder + - Retry on registry timeouts or network failures (Trent Mick) + - Reduce 'engines' failures to a warning + - Use new zsh completion if aviailable (Jeremy Cantrell) + +* Fix #3577 Un-break require('sys') + +* util: speed up formatting of large arrays/objects (Ben Noordhuis) + +* windows: make fs.realpath(Sync) work with UNC paths (Bert Belder) + +* build: fix --shared-v8 option (Ben Noordhuis) + +* doc: `detached` is a boolean (Andreas Madsen) + +* build: use proper python interpreter (Ben Noordhuis) + +* build: expand ~ in `./configure --prefix=~/a/b/c` (Ben Noordhuis) + +* build: handle CC env var with spaces (Gabriel de Perthuis) + +* build: fix V8 build when compiling with gcc 4.5 (Ben Noordhuis) + +* build: fix --shared-v8 option (Ben Noordhuis) + +* windows msi: Fix icon issue which caused huge file size (Bert Belder) + +* unix: assume that dlopen() may clobber dlerror() (Ben Noordhuis) + +* sunos: fix memory corruption bugs (Ben Noordhuis) + +* windows: better (f)utimes and (f)stat (Bert Belder) + + +2012.06.25, Version 0.8.0 (stable), 8b8a7a7f9b41e74e1e810d0330738ad06fc302ec + +* V8: upgrade to v3.11.10.10 + +* npm: Upgrade to 1.1.32 + +* Deprecate iowatcher (Ben Noordhuis) + +* windows: update icon (Bert Belder) + +* http: Hush 'MUST NOT have a body' warnings to debug() (isaacs) + +* Move blog.nodejs.org content into repository (isaacs) + +* Fix #3503: stdin: resume() on pipe(dest) (isaacs) + +* crypto: fix error reporting in SetKey() (Fedor Indutny) + +* Add --no-deprecation and --trace-deprecation command-line flags (isaacs) + +* fs: fix fs.watchFile() (Ben Noordhuis) + +* fs: Fix fs.readfile() on pipes (isaacs) + +* Rename GYP variable node_use_system_openssl to be consistent (Ryan Dahl) + + +2012.06.19, Version 0.7.12 (unstable), a72120190a8ffdbcd3d6ad2a2e6ceecd2087111e + +* npm: Upgrade to 1.1.30 + - Improved 'npm init' + - Fix the 'cb never called' error from 'oudated' and 'update' + - Add --save-bundle|-B config + - Fix isaacs/npm#2465: Make npm script and windows shims cygwin-aware + - Fix isaacs/npm#2452 Use --save(-dev|-optional) in npm rm + - `logstream` option to replace removed `logfd` (Rod Vagg) + - Read default descriptions from README.md files + +* Shims to support deprecated ev_* and eio_* methods (Ben Noordhuis) + +* #3118 net.Socket: Delay pause/resume until after connect (isaacs) + +* #3465 Add ./configure --no-ifaddrs flag (isaacs) + +* child_process: add .stdin stream to forks (Fedor Indutny) + +* build: fix `make install DESTDIR=/path` (Ben Noordhuis) + +* tls: fix off-by-one error in renegotiation check (Ben Noordhuis) + +* crypto: Fix diffie-hellman key generation UTF-8 errors (Fedor Indutny) + +* node: change the constructor name of process from EventEmitter to process (Andreas Madsen) + +* net: Prevent property access throws during close (Reid Burke) + +* querystring: improved speed and code cleanup (Felix Böhm) + +* sunos: fix assertion errors breaking fs.watch() (Fedor Indutny) + +* unix: stat: detect sub-second changes (Ben Noordhuis) + +* add stat() based file watcher (Ben Noordhuis) + + +2012.06.15, Version 0.7.11 (unstable), 5cfe0b86d5be266ef51bbba369c39e412ee51944 + +* V8: Upgrade to v3.11.10 + +* npm: Upgrade to 1.1.26 + +* doc: Improve cross-linking in API docs markdown (Ben Kelly) + +* Fix #3425: removeAllListeners should delete array (Reid Burke) + +* cluster: don't silently drop messages when the write queue gets big (Bert Belder) + +* Add Buffer.concat method (isaacs) + +* windows: make symlinks tolerant to forward slashes (Bert Belder) + +* build: Add node.d and node.1 to installer (isaacs) + +* cluster: rename worker.unqiueID to worker.id (Andreas Madsen) + +* Windows: Enable ETW events on Windows for existing DTrace probes. (Igor Zinkovsky) + +* test: bundle node-weak in test/gc so that it doesn't need to be downloaded (Nathan Rajlich) + +* Make many tests pass on Windows (Bert Belder) + +* Fix #3388 Support listening on file descriptors (isaacs) + +* Fix #3407 Add os.tmpDir() (isaacs) + +* Unbreak the snapshotted build on Windows (Bert Belder) + +* Clean up child_process.kill throws (Bert Belder) + +* crypto: make cipher/decipher accept buffer args (Ben Noordhuis) + + +2012.06.11, Version 0.7.10 (unstable), 12a32a48a30182621b3f8e9b9695d1946b53c131 + +* Roll V8 back to 3.9.24.31 + +* build: x64 target should always pass -m64 (Robert Mustacchi) + +* add NODE_EXTERN to node::Start (Joel Brandt) + +* repl: Warn about running npm commands (isaacs) + +* slab_allocator: fix crash in dtor if V8 is dead (Ben Noordhuis) + +* slab_allocator: fix leak of Persistent handles (Shigeki Ohtsu) + +* windows/msi: add node.js prompt to startmenu (Jeroen Janssen) + +* windows/msi: fix adding node to PATH (Jeroen Janssen) + +* windows/msi: add start menu links when installing (Jeroen Janssen) + +* windows: don't install x64 version into the 'program files (x86)' folder (Matt Gollob) + +* domain: Fix #3379 domain.intercept no longer passes error arg to cb (Marc Harter) + +* fs: make callbacks run in global context (Ben Noordhuis) + +* fs: enable fs.realpath on windows (isaacs) + +* child_process: expose UV_PROCESS_DETACHED as options.detached (Charlie McConnell) + +* child_process: new stdio API for .spawn() method (Fedor Indutny) + +* child_process: spawn().ref() and spawn().unref() (Fedor Indutny) + +* Upgrade npm to 1.1.25 + - Enable npm link on windows + - Properly remove sh-shim on Windows + - Abstract out registry client and logger + + +2012.05.28, Version 0.7.9 (unstable), 782277f11a753ded831439ed826448c06fc0f356 * Upgrade V8 to 3.11.1 diff --git a/LICENSE b/LICENSE index f464affffc1..adc86f22a6c 100644 --- a/LICENSE +++ b/LICENSE @@ -196,7 +196,7 @@ maintained libraries. The externally maintained libraries used by Node are: """ - C-Ares, an asynchronous DNS client, located at deps/uv/src/ares. C-Ares license - follows + follows: """ /* Copyright 1998 by the Massachusetts Institute of Technology. * @@ -215,7 +215,7 @@ maintained libraries. The externally maintained libraries used by Node are: - OpenSSL located at deps/openssl. OpenSSL is cryptographic software written by Eric Young (eay@cryptsoft.com) to provide SSL/TLS encryption. OpenSSL's - license follows + license follows: """ /* ==================================================================== * Copyright (c) 1998-2011 The OpenSSL Project. All rights reserved. @@ -225,7 +225,7 @@ maintained libraries. The externally maintained libraries used by Node are: * are met: * * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in @@ -296,11 +296,11 @@ maintained libraries. The externally maintained libraries used by Node are: 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. + IN THE SOFTWARE. """ - Closure Linter is located at tools/closure_linter. Closure's license - follows + follows: """ # Copyright (c) 2007, Google Inc. # All rights reserved. @@ -403,7 +403,7 @@ maintained libraries. The externally maintained libraries used by Node are: * Available under MIT license """ -- tools/gyp GYP is a meta-build system. GYP's license follows: +- tools/gyp. GYP is a meta-build system. GYP's license follows: """ Copyright (c) 2009 Google Inc. All rights reserved. @@ -434,7 +434,7 @@ maintained libraries. The externally maintained libraries used by Node are: OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. """ -- Zlib at deps/zlib. zlib's license follows +- Zlib at deps/zlib. zlib's license follows: """ /* zlib.h -- interface of the 'zlib' general purpose compression library version 1.2.4, March 14th, 2010 @@ -463,8 +463,8 @@ maintained libraries. The externally maintained libraries used by Node are: */ """ -- npm is a package manager program located at deps/npm. - npm's license follows: +- npm is a package manager program located at deps/npm. + npm's license follows: """ Copyright 2009-2012, Isaac Z. Schlueter (the "Original Author") All rights reserved. @@ -517,6 +517,11 @@ maintained libraries. The externally maintained libraries used by Node are: "npm Logo" created by Mathias Pettersson and Brian Hammond, used with permission. + "Gubblebum Blocky" font + Copyright (c) 2007 by Tjarda Koster, http://jelloween.deviantart.com + included for use in the npm website and documentation, + used with permission. + This program uses "node-uuid", Copyright (c) 2010 Robert Kieffer, according to the terms of the MIT license. @@ -527,8 +532,8 @@ maintained libraries. The externally maintained libraries used by Node are: according to the terms of the MIT/X11 license. """ -- tools/doc/node_modules/marked Marked is a Markdown parser. Marked's - license follows +- tools/doc/node_modules/marked. Marked is a Markdown parser. Marked's + license follows: """ Copyright (c) 2011-2012, Christopher Jeffrey (https://github.com/chjj/) @@ -551,8 +556,26 @@ maintained libraries. The externally maintained libraries used by Node are: THE SOFTWARE. """ -- src/ngx-queue.h ngx-queue.h is taken from the nginx source tree. nginx's - license follows +- test/gc/node_modules/weak. Node-weak is a node.js addon that provides garbage + collector notifications. Node-weak's license follows: + """ + Copyright (c) 2011, Ben Noordhuis + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + """ + +- src/ngx-queue.h. ngx-queue.h is taken from the nginx source tree. nginx's + license follows: """ Copyright (C) 2002-2012 Igor Sysoev Copyright (C) 2011,2012 Nginx, Inc. diff --git a/Makefile b/Makefile index a80da5141fb..51a8b3ea92c 100644 --- a/Makefile +++ b/Makefile @@ -31,7 +31,7 @@ out/Debug/node: $(MAKE) -C out BUILDTYPE=Debug out/Makefile: common.gypi deps/uv/uv.gyp deps/http_parser/http_parser.gyp deps/zlib/zlib.gyp deps/v8/build/common.gypi deps/v8/tools/gyp/v8.gyp node.gyp config.gypi - tools/gyp_node -f make + $(PYTHON) tools/gyp_node -f make install: all out/Release/node tools/installer.js install $(DESTDIR) @@ -61,16 +61,16 @@ test-http1: all test-valgrind: all $(PYTHON) tools/test.py --mode=release --valgrind simple message -node_modules/weak: +test/gc/node_modules/weak/build: @if [ ! -f node ]; then make all; fi - @if [ ! -d node_modules ]; then mkdir -p node_modules; fi - ./node deps/npm/bin/npm-cli.js install weak \ - --prefix="$(shell pwd)" --unsafe-perm # go ahead and run as root. + ./node deps/npm/node_modules/node-gyp/bin/node-gyp rebuild \ + --directory="$(shell pwd)/test/gc/node_modules/weak" \ + --nodedir="$(shell pwd)" -test-gc: all node_modules/weak +test-gc: all test/gc/node_modules/weak/build $(PYTHON) tools/test.py --mode=release gc -test-all: all node_modules/weak +test-all: all test/gc/node_modules/weak/build $(PYTHON) tools/test.py --mode=debug,release make test-npm @@ -130,7 +130,13 @@ website_files = \ out/doc/changelog.html \ $(doc_images) -doc: program $(apidoc_dirs) $(website_files) $(apiassets) $(apidocs) tools/doc/ +doc: program $(apidoc_dirs) $(website_files) $(apiassets) $(apidocs) tools/doc/ blog + +blogclean: + rm -rf out/blog + +blog: doc/blog out/Release/node tools/blog + out/Release/node tools/blog/generate.js doc/blog/ out/blog/ doc/blog.html doc/rss.xml $(apidoc_dirs): mkdir -p $@ @@ -160,6 +166,9 @@ email.md: ChangeLog tools/email-footer.md blog.html: email.md cat $< | ./node tools/doc/node_modules/.bin/marked > $@ +blog-upload: blog + rsync -r out/blog/ node@nodejs.org:~/web/nodejs.org/blog/ + website-upload: doc rsync -r out/doc/ node@nodejs.org:~/web/nodejs.org/ ssh node@nodejs.org '\ @@ -208,6 +217,17 @@ $(PKG): --out $(PKG) $(TARBALL): node out/doc + @if [ "$(shell git status --porcelain | egrep -v '^\?\? ')" = "" ]; then \ + exit 0 ; \ + else \ + echo "" >&2 ; \ + echo "The git repository is not clean." >&2 ; \ + echo "Please commit changes before building release tarball." >&2 ; \ + echo "" >&2 ; \ + git status --porcelain | egrep -v '^\?\?' >&2 ; \ + echo "" >&2 ; \ + exit 1 ; \ + fi @if [ $(shell ./node --version) = "$(VERSION)" ]; then \ exit 0; \ else \ @@ -218,11 +238,12 @@ $(TARBALL): node out/doc exit 1 ; \ fi git archive --format=tar --prefix=$(TARNAME)/ HEAD | tar xf - - mkdir -p $(TARNAME)/doc + mkdir -p $(TARNAME)/doc/api cp doc/node.1 $(TARNAME)/doc/node.1 - cp -r out/doc/api $(TARNAME)/doc/api + cp -r out/doc/api/* $(TARNAME)/doc/api/ rm -rf $(TARNAME)/deps/v8/test # too big rm -rf $(TARNAME)/doc/images # too big + find $(TARNAME)/ -type l | xargs rm # annoying on windows tar -cf $(TARNAME).tar $(TARNAME) rm -rf $(TARNAME) gzip -f -9 $(TARNAME).tar @@ -248,4 +269,4 @@ cpplint: lint: jslint cpplint -.PHONY: lint cpplint jslint bench clean docopen docclean doc dist distclean check uninstall install install-includes install-bin all program staticlib dynamiclib test test-all website-upload pkg +.PHONY: lint cpplint jslint bench clean docopen docclean doc dist distclean check uninstall install install-includes install-bin all program staticlib dynamiclib test test-all website-upload pkg blog blogclean diff --git a/benchmark/io.js b/benchmark/io.js index 505d8d03aae..1c18e05f615 100644 --- a/benchmark/io.js +++ b/benchmark/io.js @@ -62,7 +62,7 @@ function readtest(size, bsize) { function wt(tsize, bsize, done) { var start = Date.now(); - s = writetest(tsize, bsizes[0]); + s = writetest(tsize, bsize); s.addListener('close', function() { var end = Date.now(); var diff = end - start; @@ -73,7 +73,7 @@ function wt(tsize, bsize, done) { function rt(tsize, bsize, done) { var start = Date.now(); - s = readtest(tsize, bsizes[0]); + s = readtest(tsize, bsize); s.addListener('close', function() { var end = Date.now(); var diff = end - start; diff --git a/common.gypi b/common.gypi index 8b3e7c2e740..8d604141857 100644 --- a/common.gypi +++ b/common.gypi @@ -1,6 +1,6 @@ { 'variables': { - 'strict_aliasing%': 'false', # turn on/off -fstrict-aliasing + 'node_no_strict_aliasing%': 0, # turn off -fstrict-aliasing 'visibility%': 'hidden', # V8's visibility setting 'target_arch%': 'ia32', # set v8's target architecture 'host_arch%': 'ia32', # set v8's host architecture @@ -52,7 +52,7 @@ # pull in V8's postmortem metadata 'ldflags': [ '-Wl,-z,allextract' ] }], - ['strict_aliasing!="true"', { + ['node_no_strict_aliasing==1', { 'cflags': [ '-fno-strict-aliasing' ], }], ], @@ -145,6 +145,10 @@ 'cflags': [ '-m32' ], 'ldflags': [ '-m32' ], }], + [ 'target_arch=="x64"', { + 'cflags': [ '-m64' ], + 'ldflags': [ '-m64' ], + }], [ 'OS=="linux"', { 'ldflags': [ '-rdynamic' ], }], diff --git a/configure b/configure index 8633d48c31d..d324696f40d 100755 --- a/configure +++ b/configure @@ -65,20 +65,43 @@ parser.add_option("--shared-v8-libname", dest="shared_v8_libname", help="Alternative lib name to link to (default: 'v8')") +parser.add_option("--shared-openssl", + action="store_true", + dest="shared_openssl", + help="Link to a shared OpenSSl DLL instead of static linking") + +parser.add_option("--shared-openssl-includes", + action="store", + dest="shared_openssl_includes", + help="Directory containing OpenSSL header files") + +parser.add_option("--shared-openssl-libpath", + action="store", + dest="shared_openssl_libpath", + help="A directory to search for the shared OpenSSL DLLs") + +parser.add_option("--shared-openssl-libname", + action="store", + dest="shared_openssl_libname", + help="Alternative lib name to link to (default: 'crypto,ssl')") + +# deprecated parser.add_option("--openssl-use-sys", action="store_true", - dest="openssl_use_sys", - help="Use the system OpenSSL instead of one included with Node") + dest="shared_openssl", + help=optparse.SUPPRESS_HELP) +# deprecated parser.add_option("--openssl-includes", action="store", - dest="openssl_includes", - help="A directory to search for the OpenSSL includes") + dest="shared_openssl_includes", + help=optparse.SUPPRESS_HELP) +# deprecated parser.add_option("--openssl-libpath", action="store", - dest="openssl_libpath", - help="A directory to search for the OpenSSL libraries") + dest="shared_openssl_libpath", + help=optparse.SUPPRESS_HELP) parser.add_option("--no-ssl2", action="store_true", @@ -115,6 +138,16 @@ parser.add_option("--without-dtrace", dest="without_dtrace", help="Build without DTrace") +parser.add_option("--with-etw", + action="store_true", + dest="with_etw", + help="Build with ETW (default is true on Windows)") + +parser.add_option("--without-etw", + action="store_true", + dest="without_etw", + help="Build without ETW") + # CHECKME does this still work with recent releases of V8? parser.add_option("--gdb", action="store_true", @@ -126,6 +159,11 @@ parser.add_option("--dest-cpu", dest="dest_cpu", help="CPU architecture to build for. Valid values are: arm, ia32, x64") +parser.add_option("--no-ifaddrs", + action="store_true", + dest="no_ifaddrs", + help="Use on deprecated SunOS systems that do not support ifaddrs.h") + (options, args) = parser.parse_args() @@ -224,40 +262,37 @@ def host_arch(): def target_arch(): return host_arch() -def cc_version(): - try: - proc = subprocess.Popen([CC, '-v'], stderr=subprocess.PIPE) - except OSError: - return None - lines = proc.communicate()[1].split('\n') - version_line = None - for i, line in enumerate(lines): - if 'version' in line: - version_line = line - if not version_line: - return None - version = version_line.split("version")[1].strip().split()[0].split(".") - if not version: - return None - return ['LLVM' in version_line] + version + +def compiler_version(): + proc = subprocess.Popen(CC.split() + ['--version'], stdout=subprocess.PIPE) + is_clang = 'clang' in proc.communicate()[0].split('\n')[0] + + proc = subprocess.Popen(CC.split() + ['-dumpversion'], stdout=subprocess.PIPE) + version = tuple(map(int, proc.communicate()[0].split('.'))) + + return (version, is_clang) + def configure_node(o): # TODO add gdb - o['variables']['node_prefix'] = options.prefix if options.prefix else '' + o['variables']['node_prefix'] = os.path.expanduser(options.prefix or '') o['variables']['node_install_npm'] = b(not options.without_npm) o['variables']['node_install_waf'] = b(not options.without_waf) o['variables']['host_arch'] = host_arch() o['variables']['target_arch'] = options.dest_cpu or target_arch() o['default_configuration'] = 'Debug' if options.debug else 'Release' + cc_version, is_clang = compiler_version() + # turn off strict aliasing if gcc < 4.6.0 unless it's llvm-gcc # see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45883 # see http://code.google.com/p/v8/issues/detail?id=884 - o['variables']['strict_aliasing'] = b( - 'clang' in CC or cc_version() >= [False, 4, 6, 0]) + no_strict_aliasing = int(not(is_clang or cc_version >= (4,6,0))) + o['variables']['v8_no_strict_aliasing'] = no_strict_aliasing + o['variables']['node_no_strict_aliasing'] = no_strict_aliasing # clang has always supported -fvisibility=hidden, right? - if 'clang' not in CC and cc_version() < [False, 4, 0, 0]: + if not is_clang and cc_version < (4,0,0): o['variables']['visibility'] = '' # By default, enable DTrace on SunOS systems. Don't allow it on other @@ -272,6 +307,17 @@ def configure_node(o): else: o['variables']['node_use_dtrace'] = 'false' + if options.no_ifaddrs: + o['defines'] += ['SUNOS_NO_IFADDRS'] + + # By default, enable ETW on Windows. + if sys.platform.startswith('win32'): + o['variables']['node_use_etw'] = b(not options.without_etw); + elif b(options.with_etw) == 'true': + raise Exception('ETW is only supported on Windows.') + else: + o['variables']['node_use_etw'] = 'false' + def configure_libz(o): o['variables']['node_shared_zlib'] = b(options.shared_zlib) @@ -300,11 +346,11 @@ def configure_v8(o): o['libraries'] += ['-lv8'] if options.shared_v8_includes: o['include_dirs'] += [options.shared_v8_includes] - o['variables']['node_shared_v8_includes'] = options.shared_v8_includes def configure_openssl(o): o['variables']['node_use_openssl'] = b(not options.without_ssl) + o['variables']['node_shared_openssl'] = b(options.shared_openssl) if options.without_ssl: return @@ -312,25 +358,23 @@ def configure_openssl(o): if options.no_ssl2: o['defines'] += ['OPENSSL_NO_SSL2=1'] - if not options.openssl_use_sys: - o['variables']['node_use_system_openssl'] = b(False) - else: - out = pkg_config('openssl') - (libs, cflags) = out if out else ('', '') + if options.shared_openssl: + (libs, cflags) = pkg_config('openssl') or ('-lssl -lcrypto', '') - if options.openssl_libpath: - o['libraries'] += ['-L%s' % options.openssl_libpath, '-lssl', '-lcrypto'] + if options.shared_openssl_libpath: + o['libraries'] += ['-L%s' % options.shared_openssl_libpath] + + if options.shared_openssl_libname: + libnames = options.shared_openssl_libname.split(',') + o['libraries'] += ['-l%s' % s for s in libnames] else: o['libraries'] += libs.split() - if options.openssl_includes: - o['include_dirs'] += [options.openssl_includes] + if options.shared_openssl_includes: + o['include_dirs'] += [options.shared_openssl_includes] else: o['cflags'] += cflags.split() - o['variables']['node_use_system_openssl'] = b( - libs or cflags or options.openssl_libpath or options.openssl_includes) - output = { 'variables': {}, @@ -368,7 +412,8 @@ write('config.mk', "# Do not edit. Generated by the configure script.\n" + ("BUILDTYPE=%s\n" % ('Debug' if options.debug else 'Release'))) if os.name == 'nt': - subprocess.call(['python', 'tools/gyp_node', '-f', 'msvs', - '-G', 'msvs_version=2010']) + gyp_args = ['-f', 'msvs', '-G', 'msvs_version=2010'] else: - subprocess.call(['tools/gyp_node', '-f', 'make']) + gyp_args = ['-f', 'make'] + +subprocess.call([sys.executable, 'tools/gyp_node'] + gyp_args) diff --git a/deps/npm/.npmignore b/deps/npm/.npmignore index 94dc33f0040..b1d9066bde9 100644 --- a/deps/npm/.npmignore +++ b/deps/npm/.npmignore @@ -1,16 +1,16 @@ *.swp -test/bin -test/output.log -test/packages/*/node_modules -test/packages/npm-test-depends-on-spark/which-spark.log -test/packages/test-package/random-data.txt -test/root -node_modules/ronn -node_modules/.bin npm-debug.log -./npmrc -.gitignore -release/ +/test/bin +/test/output.log +/test/packages/*/node_modules +/test/packages/npm-test-depends-on-spark/which-spark.log +/test/packages/test-package/random-data.txt +/test/root +/node_modules/ronn +/node_modules/tap +/node_modules/.bin +/npmrc +/release/ # don't need these in the npm package. html/*.png diff --git a/deps/npm/AUTHORS b/deps/npm/AUTHORS index a2b8141d701..175196a675c 100644 --- a/deps/npm/AUTHORS +++ b/deps/npm/AUTHORS @@ -65,3 +65,7 @@ Jens Grunert Joost-Wim Boekesteijn Dalmais Maxence Marcus Ekwall +Aaron Stacy +Phillip Howell +Domenic Denicola +James Halliday diff --git a/deps/npm/LICENSE b/deps/npm/LICENSE index c94425929d3..3702d8a05b6 100644 --- a/deps/npm/LICENSE +++ b/deps/npm/LICENSE @@ -49,6 +49,11 @@ and are not covered by this license. "npm Logo" created by Mathias Pettersson and Brian Hammond, used with permission. +"Gubblebum Blocky" font +Copyright (c) 2007 by Tjarda Koster, http://jelloween.deviantart.com +included for use in the npm website and documentation, +used with permission. + This program uses "node-uuid", Copyright (c) 2010 Robert Kieffer, according to the terms of the MIT license. diff --git a/deps/npm/Makefile b/deps/npm/Makefile index 19efd815c92..2663075c652 100644 --- a/deps/npm/Makefile +++ b/deps/npm/Makefile @@ -121,6 +121,8 @@ docpublish: doc-publish doc-publish: doc rsync -vazu --stats --no-implied-dirs --delete html/doc/ npmjs.org:/var/www/npmjs.org/public/doc rsync -vazu --stats --no-implied-dirs --delete html/api/ npmjs.org:/var/www/npmjs.org/public/api + rsync -vazu --stats --no-implied-dirs --delete html/webfonts/ npmjs.org:/var/www/npmjs.org/public/webfonts + scp html/style.css npmjs.org:/var/www/npmjs.org/public/ zip-publish: release scp release/* npmjs.org:/var/www/npmjs.org/public/dist/ diff --git a/deps/npm/README.md b/deps/npm/README.md index d5e285ab0e6..1257f147168 100644 --- a/deps/npm/README.md +++ b/deps/npm/README.md @@ -89,21 +89,15 @@ To install the latest **unstable** development version from git: git clone https://github.com/isaacs/npm.git cd npm - git submodule update --init --recursive sudo make install # (or: `node cli.js install -gf`) If you're sitting in the code folder reading this document in your terminal, then you've already got the code. Just do: - git submodule update --init --recursive sudo make install and npm will install itself. -Note that github tarballs **do not contain submodules**, so -those won't work. You'll have to also fetch the appropriate submodules -listed in the .gitmodules file. - ## Permissions when Using npm to Install Other Stuff **tl;dr** diff --git a/deps/npm/bin/npm b/deps/npm/bin/npm index 5fbcd3b035c..07ade35e08a 100755 --- a/deps/npm/bin/npm +++ b/deps/npm/bin/npm @@ -1,6 +1,13 @@ #!/bin/sh -if [ -x "`dirname "$0"`/node.exe" ]; then - "`dirname "$0"`/node.exe" "`dirname "$0"`/node_modules/npm/bin/npm-cli.js" "$@" + +basedir=`dirname "$0"` + +case `uname` in + *CYGWIN*) basedir=`cygpath -w "$basedir"`;; +esac + +if [ -x "$basedir/node.exe" ]; then + "$basedir/node.exe" "$basedir/node_modules/npm/bin/npm-cli.js" "$@" else - node "`dirname "$0"`/node_modules/npm/bin/npm-cli.js" "$@" + node "$basedir/node_modules/npm/bin/npm-cli.js" "$@" fi diff --git a/deps/npm/bin/npm-cli.js b/deps/npm/bin/npm-cli.js index f29437093e5..a71985b37b9 100755 --- a/deps/npm/bin/npm-cli.js +++ b/deps/npm/bin/npm-cli.js @@ -15,9 +15,9 @@ if (typeof WScript !== "undefined") { process.title = "npm" -var log = require("../lib/utils/log.js") -log.waitForConfig() -log.info("ok", "it worked if it ends with") +var log = require("npmlog") +log.pause() // will be unpaused when config is loaded. +log.info("it worked if it ends with", "ok") var fs = require("graceful-fs") , path = require("path") @@ -36,7 +36,7 @@ if (path.basename(process.argv[1]).slice(-1) === "g") { process.argv.splice(1, 1, "npm", "-g") } -log.verbose(process.argv, "cli") +log.verbose("cli", process.argv) var conf = nopt(types, shorthands) npm.argv = conf.argv.remain @@ -56,8 +56,8 @@ if (conf.versions) { return } -log.info("npm@"+npm.version, "using") -log.info("node@"+process.version, "using") +log.info("using", "npm@%s", npm.version) +log.info("using", "node@%s", process.version) // make sure that this version of node works with this version of npm. var semver = require("semver") diff --git a/deps/npm/bin/read-package-json.js b/deps/npm/bin/read-package-json.js index 8c95d86e8b1..3e5a0c77f25 100755 --- a/deps/npm/bin/read-package-json.js +++ b/deps/npm/bin/read-package-json.js @@ -6,7 +6,7 @@ if (argv.length < 3) { var fs = require("fs") , file = argv[2] - , readJson = require("../lib/utils/read-json") + , readJson = require("read-package-json") readJson(file, function (er, data) { if (er) throw er diff --git a/deps/npm/doc/cli/coding-style.md b/deps/npm/doc/cli/coding-style.md index 42ac1d785f8..c505dba83f3 100644 --- a/deps/npm/doc/cli/coding-style.md +++ b/deps/npm/doc/cli/coding-style.md @@ -129,29 +129,18 @@ Just send the error message back as the first argument to the callback. Always create a new Error object with your message. Don't just return a string message to the callback. Stack traces are handy. -Use the `require("./utils/log").er` function. It takes a callback and an -error message, and returns an object that will report the message in the -event of a failure. It's quite handy. - - function myThing (args, cb) { - getData(args, function (er, data) { - if (er) return log.er(cb, "Couldn't get data")(er) - doSomethingElse(data, cb) - }) - } - function justHasToWork (cb) { - doSomething(log.er(cb, "the doSomething failed.")) - } - ## Logging +Logging is done using the [npmlog](https://github.com/isaacs/npmlog) +utility. + Please clean up logs when they are no longer helpful. In particular, logging the same object over and over again is not helpful. Logs should report what's happening so that it's easier to track down where a fault occurs. -Use appropriate log levels. The default log() function logs at the -"info" level. See `npm-config(1)` and search for "loglevel". +Use appropriate log levels. See `npm-config(1)` and search for +"loglevel". ## Case, naming, etc. diff --git a/deps/npm/doc/cli/config.md b/deps/npm/doc/cli/config.md index 3fd9cb82699..537af5ca0ea 100644 --- a/deps/npm/doc/cli/config.md +++ b/deps/npm/doc/cli/config.md @@ -117,6 +117,7 @@ The following shorthands are parsed on the command-line: * `-S`: `--save` * `-D`: `--save-dev` * `-O`: `--save-optional` +* `-B`: `--save-bundle` * `-y`: `--yes` * `-n`: `--yes false` * `ll` and `la` commands: `ls --long` @@ -167,32 +168,6 @@ then the user could change the behavior by doing: Force npm to always require authentication when accessing the registry, even for `GET` requests. -### bin-publish - -* Default: false -* Type: Boolean - -If set to true, then binary packages will be created on publish. - -This is the way to opt into the "bindist" behavior described below. - -### bindist - -* Default: Unstable node versions, `null`, otherwise - `"--"` -* Type: String or `null` - -Experimental: on stable versions of node, binary distributions will be -created with this tag. If a user then installs that package, and their -`bindist` tag is found in the list of binary distributions, they will -get that prebuilt version. - -Pre-build node packages have their preinstall, install, and postinstall -scripts stripped (since they are run prior to publishing), and do not -have their `build` directories automatically ignored. - -It's yet to be seen if this is a good idea. - ### browser * Default: OS X: `"open"`, others: `"google-chrome"` @@ -220,6 +195,27 @@ See also the `strict-ssl` config. The location of npm's cache directory. See `npm-cache(1)` +### cache-lock-stale + +* Default: 60000 (1 minute) +* Type: Number + +The number of ms before cache folder lockfiles are considered stale. + +### cache-lock-retries + +* Default: 10 +* Type: Number + +Number of times to retry to acquire a lock on cache folder lockfiles. + +### cache-lock-wait + +* Default: 10000 (10 seconds) +* Type: Number + +Number of ms to wait for cache lock files to expire. + ### cache-max * Default: Infinity @@ -291,6 +287,15 @@ set. The command to run for `npm edit` or `npm config edit`. +### engine-strict + +* Default: false +* Type: Boolean + +If set to true, then npm will stubbornly refuse to install (or even +consider installing) any package that claims to not be compatible with +the current Node.js version. + ### force * Default: false @@ -303,6 +308,38 @@ Makes various commands more forceful. * skips cache when requesting from the registry. * prevents checks against clobbering non-npm files. +### fetch-retries + +* Default: 2 +* Type: Number + +The "retries" config for the `retry` module to use when fetching +packages from the registry. + +### fetch-retry-factor + +* Default: 10 +* Type: Number + +The "factor" config for the `retry` module to use when fetching +packages. + +### fetch-retry-mintimeout + +* Default: 10000 (10 seconds) +* Type: Number + +The "minTimeout" config for the `retry` module to use when fetching +packages. + +### fetch-retry-maxtimeout + +* Default: 60000 (1 minute) +* Type: Number + +The "maxTimeout" config for the `retry` module to use when fetching +packages. + ### git * Default: `"git"` @@ -375,6 +412,16 @@ Sets a User-Agent to the request header A white-space separated list of glob patterns of files to always exclude from packages when building tarballs. +### init-module + +* Default: ~/.npm-init.js +* Type: path + +A module that will be loaded by the `npm init` command. See the +documentation for the +[init-package-json](https://github.com/isaacs/init-package-json) module +for more information, or npm-init(1). + ### init.version * Default: "0.0.0" @@ -430,13 +477,6 @@ if one of the two conditions are met: * the globally installed version is identical to the version that is being installed locally. -### logfd - -* Default: stderr file descriptor -* Type: Number or Stream - -The location to write log output. - ### loglevel * Default: "http" @@ -449,13 +489,17 @@ What level of logs to report. On failure, *all* logs are written to Any logs of a higher level than the setting are shown. The default is "http", which shows http, warn, and error output. -### logprefix +### logstream -* Default: true on Posix, false on Windows -* Type: Boolean +* Default: process.stderr +* Type: Stream + +This is the stream that is passed to the +[npmlog](https://github.com/isaacs/npmlog) module at run time. -Whether or not to prefix log messages with "npm" and the log level. See -also "color" and "loglevel". +It cannot be set from the command line, but if you are using npm +programmatically, you may wish to send logs to somewhere other than +stderr. ### long @@ -503,13 +547,6 @@ The url to report npat test results. A node module to `require()` when npm loads. Useful for programmatic usage. -### outfd - -* Default: standard output file descriptor -* Type: Number or Stream - -Where to write "normal" output. This has no effect on log output. - ### parseable * Default: false @@ -584,8 +621,23 @@ Remove failed installs. Save installed packages to a package.json file as dependencies. +When used with the `npm rm` command, it removes it from the dependencies +hash. + Only works if there is already a package.json file present. +### save-bundle + +* Default: false +* Type: Boolean + +If a package would be saved at install time by the use of `--save`, +`--save-dev`, or `--save-optional`, then also put it in the +`bundleDependencies` list. + +When used with the `npm rm` command, it removes it from the +bundledDependencies list. + ### save-dev * Default: false @@ -593,6 +645,9 @@ Only works if there is already a package.json file present. Save installed packages to a package.json file as devDependencies. +When used with the `npm rm` command, it removes it from the devDependencies +hash. + Only works if there is already a package.json file present. ### save-optional @@ -602,6 +657,9 @@ Only works if there is already a package.json file present. Save installed packages to a package.json file as optionalDependencies. +When used with the `npm rm` command, it removes it from the devDependencies +hash. + Only works if there is already a package.json file present. ### searchopts diff --git a/deps/npm/doc/cli/init.md b/deps/npm/doc/cli/init.md index 39297b4c4d6..d036f924db2 100644 --- a/deps/npm/doc/cli/init.md +++ b/deps/npm/doc/cli/init.md @@ -20,5 +20,6 @@ without a really good reason to do so. ## SEE ALSO +* * npm-json(1) * npm-version(1) diff --git a/deps/npm/doc/cli/install.md b/deps/npm/doc/cli/install.md index cfa95e72297..1d2f6eca8f8 100644 --- a/deps/npm/doc/cli/install.md +++ b/deps/npm/doc/cli/install.md @@ -160,7 +160,7 @@ local copy exists on disk. npm install sax --force The `--global` argument will cause npm to install the package globally -rather than locally. See `npm-global(1)`. +rather than locally. See `npm-folders(1)`. The `--link` argument will cause npm to link global installs into the local space in some cases. diff --git a/deps/npm/doc/cli/json.md b/deps/npm/doc/cli/json.md index ddd500e3b12..b6bf89ca37f 100644 --- a/deps/npm/doc/cli/json.md +++ b/deps/npm/doc/cli/json.md @@ -394,6 +394,7 @@ Git urls can be of the form: git://github.com/user/project.git#commit-ish git+ssh://user@hostname:project.git#commit-ish + git+ssh://user@hostname/project.git#commit-ish git+http://user@hostname/project/blah.git#commit-ish git+https://user@hostname/project/blah.git#commit-ish @@ -420,10 +421,39 @@ Array of package names that will be bundled when publishing the package. If this is spelled `"bundleDependencies"`, then that is also honorable. +## optionalDependencies + +If a dependency can be used, but you would like npm to proceed if it +cannot be found or fails to install, then you may put it in the +`optionalDependencies` hash. This is a map of package name to version +or url, just like the `dependencies` hash. The difference is that +failure is tolerated. + +It is still your program's responsibility to handle the lack of the +dependency. For example, something like this: + + try { + var foo = require('foo') + var fooVersion = require('foo/package.json').version + } catch (er) { + foo = null + } + if ( notGoodFooVersion(fooVersion) ) { + foo = null + } + + // .. then later in your program .. + + if (foo) { + foo.doFooThings() + } + +Entries in `optionalDependencies` will override entries of the same name in +`dependencies`, so it's usually best to only put in one place. + ## engines -You can specify the version of -node that your stuff works on: +You can specify the version of node that your stuff works on: { "engines" : { "node" : ">=0.1.27 <0.1.30" } } @@ -439,6 +469,22 @@ are capable of properly installing your program. For example: { "engines" : { "npm" : "~1.0.20" } } +Note that, unless the user has set the `engine-strict` config flag, this +field is advisory only. + +## engineStrict + +If you are sure that your module will *definitely not* run properly on +versions of Node/npm other than those specified in the `engines` hash, +then you can set `"engineStrict": true` in your package.json file. +This will override the user's `engine-strict` config setting. + +Please do not do this unless you are really very very sure. If your +engines hash is something overly restrictive, you can quite easily and +inadvertently lock yourself into obscurity and prevent your users from +updating to new versions of Node. Consider this choice carefully. If +people abuse it, it will be removed in a future version of npm. + ## os You can specify which operating systems your diff --git a/deps/npm/html/api/GubbleBum-Blocky.ttf b/deps/npm/html/api/GubbleBum-Blocky.ttf deleted file mode 100755 index 8eac02f7ada..00000000000 Binary files a/deps/npm/html/api/GubbleBum-Blocky.ttf and /dev/null differ diff --git a/deps/npm/html/api/author.html b/deps/npm/html/api/author.html deleted file mode 100644 index 0625fbc183e..00000000000 --- a/deps/npm/html/api/author.html +++ /dev/null @@ -1,69 +0,0 @@ - - - author - - - - -
-

owner

Manage package owners

- -

SYNOPSIS

- -
npm.commands.owner(args, callback)
- -

DESCRIPTION

- -

The first element of the 'args' parameter defines what to do, and the subsequent -elements depend on the action. Possible values for the action are (order of -parameters are given in parenthesis):

- -
  • ls (package): -List all the users who have access to modify a package and push new versions. -Handy when you need to know who to bug for help.
  • add (user, package): -Add a new user as a maintainer of a package. This user is enabled to modify -metadata, publish new versions, and add other owners.
  • rm (user, package): -Remove a user from the package owner list. This immediately revokes their -privileges.
- -

Note that there is only one level of access. Either you can modify a package, -or you can't. Future versions may contain more fine-grained access levels, but -that is not implemented at this time.

- -

SEE ALSO

- - -
- - - diff --git a/deps/npm/html/api/bin.html b/deps/npm/html/api/bin.html index 110729f2656..4e62af70191 100644 --- a/deps/npm/html/api/bin.html +++ b/deps/npm/html/api/bin.html @@ -2,7 +2,7 @@ bin - +
@@ -19,7 +19,7 @@

DESCRIPTION

This function should not be used programmatically. Instead, just refer to the npm.bin member.

- + - diff --git a/deps/npm/html/api/get.html b/deps/npm/html/api/get.html deleted file mode 100644 index 46d372ad6b0..00000000000 --- a/deps/npm/html/api/get.html +++ /dev/null @@ -1,68 +0,0 @@ - - - get - - - - -
-

config

Manage the npm configuration files

- -

SYNOPSIS

- -
npm.commands.config(args, callback)
-var val = npm.config.get(key)
-npm.config.set(key, val)
- -

DESCRIPTION

- -

This function acts much the same way as the command-line version. The first -element in the array tells config what to do. Possible values are:

- -
  • set

    Sets a config parameter. The second element in args is interpreted as the -key, and the third element is interpreted as the value.

  • get

    Gets the value of a config parameter. The second element in args is the -key to get the value of.

  • delete (rm or del)

    Deletes a parameter from the config. The second element in args is the -key to delete.

  • list (ls)

    Show all configs that aren't secret. No parameters necessary.

  • edit:

    Opens the config file in the default editor. This command isn't very useful -programmatically, but it is made available.

- -

To programmatically access npm configuration settings, or set them for -the duration of a program, use the npm.config.set and npm.config.get -functions instead.

- -

SEE ALSO

- - -
- - - diff --git a/deps/npm/html/api/help-search.html b/deps/npm/html/api/help-search.html index d0e83825796..44c72bad043 100644 --- a/deps/npm/html/api/help-search.html +++ b/deps/npm/html/api/help-search.html @@ -2,7 +2,7 @@ help-search - +
@@ -32,7 +32,7 @@

DESCRIPTION

The silent parameter is not neccessary not used, but it may in the future.

- + - diff --git a/deps/npm/html/api/init.html b/deps/npm/html/api/init.html index 400e61a3d60..84854dbb1e8 100644 --- a/deps/npm/html/api/init.html +++ b/deps/npm/html/api/init.html @@ -2,7 +2,7 @@ init - +
@@ -35,7 +35,7 @@

SEE ALSO

json(1)

- + - diff --git a/deps/npm/html/api/ln.html b/deps/npm/html/api/ln.html deleted file mode 100644 index 0629e06425e..00000000000 --- a/deps/npm/html/api/ln.html +++ /dev/null @@ -1,74 +0,0 @@ - - - ln - - - - -
-

link

Symlink a package folder

- -

SYNOPSIS

- -
npm.command.link(callback)
-npm.command.link(packages, callback)
- -

DESCRIPTION

- -

Package linking is a two-step process.

- -

Without parameters, link will create a globally-installed -symbolic link from prefix/package-name to the current folder.

- -

With a parameters, link will create a symlink from the local node_modules -folder to the global symlink.

- -

When creating tarballs for npm publish, the linked packages are -"snapshotted" to their current state by resolving the symbolic links.

- -

This is -handy for installing your own stuff, so that you can work on it and test it -iteratively without having to continually rebuild.

- -

For example:

- -
npm.commands.link(cb)           # creates global link from the cwd
-                                # (say redis package)
-npm.commands.link('redis', cb)  # link-install the package
- -

Now, any changes to the redis package will be reflected in -the package in the current working directory

-
- - - diff --git a/deps/npm/html/api/load.html b/deps/npm/html/api/load.html index c88f9addd00..3a28add38e0 100644 --- a/deps/npm/html/api/load.html +++ b/deps/npm/html/api/load.html @@ -2,7 +2,7 @@ load - +
@@ -32,7 +32,7 @@

DESCRIPTION

For a list of all the available command-line configs, see npm help config

- + - diff --git a/deps/npm/html/api/root.html b/deps/npm/html/api/root.html index b9c8c272028..a1746c3f94b 100644 --- a/deps/npm/html/api/root.html +++ b/deps/npm/html/api/root.html @@ -2,7 +2,7 @@ root - +
@@ -21,7 +21,7 @@

DESCRIPTION

This function is not useful programmatically.

- + - diff --git a/deps/npm/html/api/shrinkwrap.html b/deps/npm/html/api/shrinkwrap.html index 1b25f128822..9587c4b96e0 100644 --- a/deps/npm/html/api/shrinkwrap.html +++ b/deps/npm/html/api/shrinkwrap.html @@ -2,7 +2,7 @@ shrinkwrap - +
@@ -26,7 +26,7 @@

DESCRIPTION

Finally, 'callback' is a function that will be called when the shrinkwrap has been saved.

- + - diff --git a/deps/npm/html/doc/bin.html b/deps/npm/html/doc/bin.html index 043f6fd8da4..ec24d4f75c7 100644 --- a/deps/npm/html/doc/bin.html +++ b/deps/npm/html/doc/bin.html @@ -2,7 +2,7 @@ bin - +
@@ -20,7 +20,7 @@

SEE ALSO

- + - diff --git a/deps/npm/html/doc/folders.html b/deps/npm/html/doc/folders.html index 1ee33de7f40..1a10bd3d347 100644 --- a/deps/npm/html/doc/folders.html +++ b/deps/npm/html/doc/folders.html @@ -2,7 +2,7 @@ folders - + - + - diff --git a/deps/npm/html/doc/global.html b/deps/npm/html/doc/global.html deleted file mode 100644 index 9904c30ce51..00000000000 --- a/deps/npm/html/doc/global.html +++ /dev/null @@ -1,240 +0,0 @@ - - - global - - - - -
-

folders

Folder Structures Used by npm

- -

DESCRIPTION

- -

npm puts various things on your computer. That's its job.

- -

This document will tell you what it puts where.

- -

tl;dr

- -
  • Local install (default): puts stuff in ./node_modules of the current -package root.
  • Global install (with -g): puts stuff in /usr/local or wherever node -is installed.
  • Install it locally if you're going to require() it.
  • Install it globally if you're going to run it on the command line.
  • If you need both, then install it in both places, or use npm link.
- -

prefix Configuration

- -

The prefix config defaults to the location where node is installed. -On most systems, this is /usr/local, and most of the time is the same -as node's process.installPrefix.

- -

On windows, this is the exact location of the node.exe binary. On Unix -systems, it's one level up, since node is typically installed at -{prefix}/bin/node rather than {prefix}/node.exe.

- -

When the global flag is set, npm installs things into this prefix. -When it is not set, it uses the root of the current package, or the -current working directory if not in a package already.

- -

Node Modules

- -

Packages are dropped into the node_modules folder under the prefix. -When installing locally, this means that you can -require("packagename") to load its main module, or -require("packagename/lib/path/to/sub/module") to load other modules.

- -

Global installs on Unix systems go to {prefix}/lib/node_modules. -Global installs on Windows go to {prefix}/node_modules (that is, no -lib folder.)

- -

If you wish to require() a package, then install it locally.

- -

Executables

- -

When in global mode, executables are linked into {prefix}/bin on Unix, -or directly into {prefix} on Windows.

- -

When in local mode, executables are linked into -./node_modules/.bin so that they can be made available to scripts run -through npm. (For example, so that a test runner will be in the path -when you run npm test.)

- -

Man Pages

- -

When in global mode, man pages are linked into {prefix}/share/man.

- -

When in local mode, man pages are not installed.

- -

Man pages are not installed on Windows systems.

- -

Cache

- -

See cache(1). Cache files are stored in ~/.npm on Posix, or -~/npm-cache on Windows.

- -

This is controlled by the cache configuration param.

- -

Temp Files

- -

Temporary files are stored by default in the folder specified by the -tmp config, which defaults to the TMPDIR, TMP, or TEMP environment -variables, or /tmp on Unix and c:\windows\temp on Windows.

- -

Temp files are given a unique folder under this root for each run of the -program, and are deleted upon successful exit.

- -

More Information

- -

When installing locally, npm first tries to find an appropriate -prefix folder. This is so that npm install foo@1.2.3 will install -to the sensible root of your package, even if you happen to have cded -into some other folder.

- -

Starting at the $PWD, npm will walk up the folder tree checking for a -folder that contains either a package.json file, or a node_modules -folder. If such a thing is found, then that is treated as the effective -"current directory" for the purpose of running npm commands. (This -behavior is inspired by and similar to git's .git-folder seeking -logic when running git commands in a working dir.)

- -

If no package root is found, then the current folder is used.

- -

When you run npm install foo@1.2.3, then the package is loaded into -the cache, and then unpacked into ./node_modules/foo. Then, any of -foo's dependencies are similarly unpacked into -./node_modules/foo/node_modules/....

- -

Any bin files are symlinked to ./node_modules/.bin/, so that they may -be found by npm scripts when necessary.

- -

Global Installation

- -

If the global configuration is set to true, then npm will -install packages "globally".

- -

For global installation, packages are installed roughly the same way, -but using the folders described above.

- -

Cycles, Conflicts, and Folder Parsimony

- -

Cycles are handled using the property of node's module system that it -walks up the directories looking for node_modules folders. So, at every -stage, if a package is already installed in an ancestor node_modules -folder, then it is not installed at the current location.

- -

Consider the case above, where foo -> bar -> baz. Imagine if, in -addition to that, baz depended on bar, so you'd have: -foo -> bar -> baz -> bar -> baz .... However, since the folder -structure is: foo/node_modules/bar/node_modules/baz, there's no need to -put another copy of bar into .../baz/node_modules, since when it calls -require("bar"), it will get the copy that is installed in -foo/node_modules/bar.

- -

This shortcut is only used if the exact same -version would be installed in multiple nested node_modules folders. It -is still possible to have a/node_modules/b/node_modules/a if the two -"a" packages are different versions. However, without repeating the -exact same package multiple times, an infinite regress will always be -prevented.

- -

Another optimization can be made by installing dependencies at the -highest level possible, below the localized "target" folder.

- -

Example

- -

Consider this dependency graph:

- -
foo
-+-- blerg@1.2.5
-+-- bar@1.2.3
-|   +-- blerg@1.x (latest=1.3.7)
-|   +-- baz@2.x
-|   |   `-- quux@3.x
-|   |       `-- bar@1.2.3 (cycle)
-|   `-- asdf@*
-`-- baz@1.2.3
-    `-- quux@3.x
-        `-- bar
- -

In this case, we might expect a folder structure like this:

- -
foo
-+-- node_modules
-    +-- blerg (1.2.5) <---[A]
-    +-- bar (1.2.3) <---[B]
-    |   +-- node_modules
-    |   |   `-- baz (2.0.2) <---[C]
-    |   |       `-- node_modules
-    |   |           `-- quux (3.2.0)
-    |   `-- asdf (2.3.4)
-    `-- baz (1.2.3) <---[D]
-        `-- node_modules
-            `-- quux (3.2.0) <---[E]
- -

Since foo depends directly on bar@1.2.3 and baz@1.2.3, those are -installed in foo's node_modules folder.

- -

Even though the latest copy of blerg is 1.3.7, foo has a specific -dependency on version 1.2.5. So, that gets installed at [A]. Since the -parent installation of blerg satisfie's bar's dependency on blerg@1.x, -it does not install another copy under [B].

- -

Bar [B] also has dependencies on baz and asdf, so those are installed in -bar's node_modules folder. Because it depends on baz@2.x, it cannot -re-use the baz@1.2.3 installed in the parent node_modules folder [D], -and must install its own copy [C].

- -

Underneath bar, the baz->quux->bar dependency creates a cycle. -However, because bar is already in quux's ancestry [B], it does not -unpack another copy of bar into that folder.

- -

Underneath foo->baz [D], quux's [E] folder tree is empty, because its -dependency on bar is satisfied by the parent folder copy installed at [B].

- -

For a graphical breakdown of what is installed where, use npm ls.

- -

Publishing

- -

Upon publishing, npm will look in the node_modules folder. If any of -the items there are not in the bundledDependencies array, then they will -not be included in the package tarball.

- -

This allows a package maintainer to install all of their dependencies -(and dev dependencies) locally, but only re-publish those items that -cannot be found elsewhere. See json(1) for more information.

- -

SEE ALSO

- - -
- - - diff --git a/deps/npm/html/doc/help-search.html b/deps/npm/html/doc/help-search.html index 7690a717eec..d0ecc6cbb8a 100644 --- a/deps/npm/html/doc/help-search.html +++ b/deps/npm/html/doc/help-search.html @@ -2,7 +2,7 @@ help-search - +
@@ -38,7 +38,7 @@

SEE ALSO

- + - diff --git a/deps/npm/html/doc/index.html b/deps/npm/html/doc/index.html index 9082ff85ba0..2a1b92a690b 100644 --- a/deps/npm/html/doc/index.html +++ b/deps/npm/html/doc/index.html @@ -2,7 +2,7 @@ index - +
@@ -384,7 +384,7 @@

whoami(3)

Display npm username

- + - diff --git a/deps/npm/html/doc/ls.html b/deps/npm/html/doc/ls.html deleted file mode 100644 index 9ad1fca2787..00000000000 --- a/deps/npm/html/doc/ls.html +++ /dev/null @@ -1,87 +0,0 @@ - - - ls - - - - -
-

ls

List installed packages

- -

SYNOPSIS

- -
npm list
-npm ls
-npm la
-npm ll
- -

DESCRIPTION

- -

This command will print to stdout all the versions of packages that are -installed, as well as their dependencies, in a tree-structure.

- -

It does not take positional arguments, though you may set config flags -like with any other command, such as -g to list global packages.

- -

It will print out extraneous, missing, and invalid packages.

- -

When run as ll or la, it shows extended information by default.

- -

CONFIGURATION

- -

long

- -
  • Default: false
  • Type: Boolean
- -

Show extended information.

- -

parseable

- -
  • Default: false
  • Type: Boolean
- -

Show parseable output instead of tree view.

- -

global

- -
  • Default: false
  • Type: Boolean
- -

List packages in the global install prefix instead of in the current -project.

- -

SEE ALSO

- - -
- - - diff --git a/deps/npm/html/doc/npm.html b/deps/npm/html/doc/npm.html index 6f71723b2cb..179d1b2745e 100644 --- a/deps/npm/html/doc/npm.html +++ b/deps/npm/html/doc/npm.html @@ -2,7 +2,7 @@ npm - +
@@ -14,7 +14,7 @@

SYNOPSIS

VERSION

-

1.1.23

+

1.1.33

DESCRIPTION

@@ -135,7 +135,7 @@

SEE ALSO

- + - diff --git a/deps/npm/html/doc/root.html b/deps/npm/html/doc/root.html index ea583953c88..b30b42a3e63 100644 --- a/deps/npm/html/doc/root.html +++ b/deps/npm/html/doc/root.html @@ -2,7 +2,7 @@ root - +
@@ -20,7 +20,7 @@

SEE ALSO

- + - diff --git a/deps/npm/html/doc/shrinkwrap.html b/deps/npm/html/doc/shrinkwrap.html index 5e9a4017237..26237b4761b 100644 --- a/deps/npm/html/doc/shrinkwrap.html +++ b/deps/npm/html/doc/shrinkwrap.html @@ -2,7 +2,7 @@ shrinkwrap - +
@@ -169,7 +169,7 @@

SEE ALSO

- + - + diff --git a/doc/api/_toc.markdown b/doc/api/_toc.markdown index 0e90fe6c765..d8da1740e2e 100644 --- a/doc/api/_toc.markdown +++ b/doc/api/_toc.markdown @@ -23,6 +23,7 @@ * [HTTPS](https.html) * [URL](url.html) * [Query Strings](querystring.html) +* [Punycode](punycode.html) * [Readline](readline.html) * [REPL](repl.html) * [VM](vm.html) diff --git a/doc/api/all.markdown b/doc/api/all.markdown index c62526713e4..044c0aee974 100644 --- a/doc/api/all.markdown +++ b/doc/api/all.markdown @@ -23,6 +23,7 @@ @include https @include url @include querystring +@include punycode @include readline @include repl @include vm diff --git a/doc/api/buffer.markdown b/doc/api/buffer.markdown index 82a36eedc6f..ff95304ed6f 100644 --- a/doc/api/buffer.markdown +++ b/doc/api/buffer.markdown @@ -148,6 +148,26 @@ Example: // ½ + ¼ = ¾: 9 characters, 12 bytes +### Class Method: Buffer.concat(list, [totalLength]) + +* `list` {Array} List of Buffer objects to concat +* `totalLength` {Number} Total length of the buffers when concatenated + +Returns a buffer which is the result of concatenating all the buffers in +the list together. + +If the list has no items, or if the totalLength is 0, then it returns a +zero-length buffer. + +If the list has exactly one item, then the first item of the list is +returned. + +If the list has more than one item, then a new Buffer is created. + +If totalLength is not provided, it is read from the buffers in the list. +However, this adds an additional loop to the function, so it is faster +to provide the length explicitly. + ### buf.length * Number diff --git a/doc/api/child_process.markdown b/doc/api/child_process.markdown index e9aab649f4b..99f72db7f67 100644 --- a/doc/api/child_process.markdown +++ b/doc/api/child_process.markdown @@ -14,7 +14,7 @@ different, and explained below. ## Class: ChildProcess -`ChildProcess` is an `EventEmitter`. +`ChildProcess` is an [EventEmitter][]. Child processes always have three streams associated with them. `child.stdin`, `child.stdout`, and `child.stderr`. These may be shared with the stdio @@ -249,7 +249,7 @@ there is no IPC channel keeping it alive. When calling this method the * `customFds` {Array} **Deprecated** File descriptors for the child to use for stdio. (See below) * `env` {Object} Environment key-value pairs - * `setsid` {Boolean} + * `detached` {Boolean} The child will be a process group leader. (See below) * return: {ChildProcess object} Launches a new process with the given `command`, with command line arguments in `args`. @@ -340,22 +340,31 @@ API. The 'stdio' option to `child_process.spawn()` is an array where each index corresponds to a fd in the child. The value is one of the following: -1. `null`, `undefined` - Use default value. For 0,1,2 stdios this is the same - as `'pipe'`. For any higher value, `'ignore'` -2. `'ignore'` - Open the fd in the child, but do not expose it to the parent -3. `'pipe'` - Open the fd and expose as a `Stream` object to parent. -4. `'ipc'` - Create IPC channel for passing messages/file descriptors between - parent and child. - - Note: A ChildProcess may have at most *one* IPC stdio file descriptor. - Setting this option enables the ChildProcess.send() method. If the - child writes JSON messages to this file descriptor, then this will trigger - ChildProcess.on('message'). If the child is a Node.js program, then - the presence of an IPC channel will enable process.send() and - process.on('message') -5. positive integer - Share corresponding fd with child -6. Any TTY, TCP, File stream (or any object with `fd` property) - Share - corresponding stream with child. +1. `'pipe'` - Create a pipe between the child process and the parent process. + The parent end of the pipe is exposed to the parent as a property on the + `child_process` object as `ChildProcess.stdio[fd]`. Pipes created for + fds 0 - 2 are also available as ChildProcess.stdin, ChildProcess.stdout + and ChildProcess.stderr, respectively. +2. `'ipc'` - Create an IPC channel for passing messages/file descriptors + between parent and child. A ChildProcess may have at most *one* IPC stdio + file descriptor. Setting this option enables the ChildProcess.send() method. + If the child writes JSON messages to this file descriptor, then this will + trigger ChildProcess.on('message'). If the child is a Node.js program, then + the presence of an IPC channel will enable process.send() and + process.on('message'). +3. `'ignore'` - Do not set this file descriptor in the child. Note that Node + will always open fd 0 - 2 for the processes it spawns. When any of these is + ignored node will open `/dev/null` and attach it to the child's fd. +4. `Stream` object - Share a readable or writable stream that refers to a tty, + file, socket, or a pipe with the child process. The stream's underlying + file descriptor is duplicated in the child process to the fd that + corresponds to the index in the `stdio` array. +5. Positive integer - The integer value is interpreted as a file descriptor + that is is currently open in the parent process. It is shared with the child + process, similar to how `Stream` objects can be shared. +6. `null`, `undefined` - Use default value. For stdio fds 0, 1 and 2 (in other + words, stdin, stdout, and stderr) a pipe is created. For fd 3 and up, the + default is `'ignore'`. As a shorthand, the `stdio` argument may also be one of the following strings, rather than an array: @@ -378,6 +387,34 @@ Example: // startd-style interface. spawn('prg', [], { stdio: ['pipe', null, null, null, 'pipe'] }); +If the `detached` option is set, the child process will be made the leader of a +new process group. This makes it possible for the child to continue running +after the parent exits. + +By default, the parent will wait for the detached child to exit. To prevent +the parent from waiting for a given `child`, use the `child.unref()` method, +and the parent's event loop will not include the child in its reference count. + +Example of detaching a long-running process and redirecting its output to a +file: + + var fs = require('fs'), + spawn = require('child_process').spawn, + out = fs.openSync('./out.log', 'a'), + err = fs.openSync('./out.log', 'a'); + + var child = spawn('prg', [], { + detached: true, + stdio: [ 'ignore', out, err ] + }); + + child.unref(); + +When using the `detached` option to start a long-running process, the process +will not stay running in the background unless it is provided with a `stdio` +configuration that is not connected to the parent. If the parent's `stdio` is +inherited, the child will remain attached to the controlling terminal. + There is a deprecated option called `customFds` which allows one to specify specific file descriptors for the stdio of the child process. This API was not portable to all platforms and therefore removed. @@ -400,7 +437,6 @@ See also: `child_process.exec()` and `child_process.fork()` * `customFds` {Array} **Deprecated** File descriptors for the child to use for stdio. (See above) * `env` {Object} Environment key-value pairs - * `setsid` {Boolean} * `encoding` {String} (Default: 'utf8') * `timeout` {Number} (Default: 0) * `maxBuffer` {Number} (Default: 200*1024) @@ -458,10 +494,9 @@ the child process is killed. * `customFds` {Array} **Deprecated** File descriptors for the child to use for stdio. (See above) * `env` {Object} Environment key-value pairs - * `setsid` {Boolean} * `encoding` {String} (Default: 'utf8') * `timeout` {Number} (Default: 0) - * `maxBuffer` {Number} (Default: 200*1024) + * `maxBuffer` {Number} (Default: 200\*1024) * `killSignal` {String} (Default: 'SIGTERM') * `callback` {Function} called with the output when process terminates * `error` {Error} @@ -474,14 +509,13 @@ subshell but rather the specified file directly. This makes it slightly leaner than `child_process.exec`. It has the same options. -## child_process.fork(modulePath, [args], [options]) +## child\_process.fork(modulePath, [args], [options]) * `modulePath` {String} The module to run in the child * `args` {Array} List of string arguments * `options` {Object} * `cwd` {String} Current working directory of the child process * `env` {Object} Environment key-value pairs - * `setsid` {Boolean} * `encoding` {String} (Default: 'utf8') * `timeout` {Number} (Default: 0) * Return: ChildProcess object @@ -498,3 +532,5 @@ with the parent's. To change this behavior set the `silent` property in the These child Nodes are still whole new instances of V8. Assume at least 30ms startup and 10mb memory for each new Node. That is, you cannot create many thousands of them. + +[EventEmitter]: events.html#events_class_events_eventemitter diff --git a/doc/api/cluster.markdown b/doc/api/cluster.markdown index 3b67a33bfe4..bb1a77c980c 100644 --- a/doc/api/cluster.markdown +++ b/doc/api/cluster.markdown @@ -41,6 +41,55 @@ Running node will now share port 8000 between the workers: This feature was introduced recently, and may change in future versions. Please try it out and provide feedback. +Also note that, on Windows, it is not yet possible to set up a named pipe +server in a worker. + +## How It Works + + + +The worker processes are spawned using the `child_process.fork` method, +so that they can communicate with the parent via IPC and pass server +handles back and forth. + +When you call `server.listen(...)` in a worker, it serializes the +arguments and passes the request to the master process. If the master +process already has a listening server matching the worker's +requirements, then it passes the handle to the worker. If it does not +already have a listening server matching that requirement, then it will +create one, and pass the handle to the child. + +This causes potentially surprising behavior in three edge cases: + +1. `server.listen({fd: 7})` Because the message is passed to the master, + file descriptor 7 **in the parent** will be listened on, and the + handle passed to the worker, rather than listening to the worker's + idea of what the number 7 file descriptor references. +2. `server.listen(handle)` Listening on handles explicitly will cause + the worker to use the supplied handle, rather than talk to the master + process. If the worker already has the handle, then it's presumed + that you know what you are doing. +3. `server.listen(0)` Normally, this will case servers to listen on a + random port. However, in a cluster, each worker will receive the + same "random" port each time they do `listen(0)`. In essence, the + port is random the first time, but predictable thereafter. If you + want to listen on a unique port, generate a port number based on the + cluster worker ID. + +When multiple processes are all `accept()`ing on the same underlying +resource, the operating system load-balances across them very +efficiently. There is no routing logic in Node.js, or in your program, +and no shared state between the workers. Therefore, it is important to +design your program such that it does not rely too heavily on in-memory +data objects for things like sessions and login. + +Because workers are all separate processes, they can be killed or +re-spawned depending on your program's needs, without affecting other +workers. As long as there are some workers still alive, the server will +continue to accept connections. Node does not automatically manage the +number of workers for you, however. It is your responsibility to manage +the worker pool for your application's needs. + ## cluster.settings * {Object} @@ -82,13 +131,13 @@ This can be used to log worker activity, or to create your own timeout. } cluster.on('fork', function(worker) { - timeouts[worker.uniqueID] = setTimeout(errorMsg, 2000); + timeouts[worker.id] = setTimeout(errorMsg, 2000); }); cluster.on('listening', function(worker, address) { - clearTimeout(timeouts[worker.uniqueID]); + clearTimeout(timeouts[worker.id]); }); cluster.on('exit', function(worker, code, signal) { - clearTimeout(timeouts[worker.uniqueID]); + clearTimeout(timeouts[worker.id]); errorMsg(); }); @@ -137,13 +186,13 @@ the process is stuck in a cleanup or if there are long-living connections. cluster.on('disconnect', function(worker) { - console.log('The worker #' + worker.uniqueID + ' has disconnected'); + console.log('The worker #' + worker.id + ' has disconnected'); }); ## Event: 'exit' * `worker` {Worker object} -* `code` {Number} the exit code, if it exited normally. +* `code` {Number} the exit code, if it exited normally. * `signal` {String} the name of the signal (eg. `'SIGHUP'`) that caused the process to be killed. @@ -184,7 +233,7 @@ Example: args : ["--use", "https"], silent : true }); - cluster.autoFork(); + cluster.fork(); ## cluster.fork([env]) @@ -219,13 +268,13 @@ The method takes an optional callback argument which will be called when finishe * {Object} -In the cluster, all living worker objects are stored in this object with their -`uniqueID` as the key. This makes it easy to loop through all living workers. +In the cluster, all living worker objects are stored in this object by there +`id` as the key. This makes it easy to loop through all living workers. // Go through all workers function eachWorker(callback) { - for (var uniqueID in cluster.workers) { - callback(cluster.workers[uniqueID]); + for (var id in cluster.workers) { + callback(cluster.workers[id]); } } eachWorker(function(worker) { @@ -233,10 +282,10 @@ In the cluster, all living worker objects are stored in this object with their }); Should you wish to reference a worker over a communication channel, using -the worker's uniqueID is the easiest way to find the worker. +the worker's unique id is the easiest way to find the worker. - socket.on('data', function(uniqueID) { - var worker = cluster.workers[uniqueID]; + socket.on('data', function(id) { + var worker = cluster.workers[id]; }); ## Class: Worker @@ -245,12 +294,12 @@ A Worker object contains all public information and method about a worker. In the master it can be obtained using `cluster.workers`. In a worker it can be obtained using `cluster.worker`. -### worker.uniqueID +### worker.id * {String} Each new worker is given its own unique id, this id is stored in the -`uniqueID`. +`id`. While a worker is alive, this is the key that indexes it in cluster.workers @@ -386,9 +435,13 @@ in the master process using the message system: } // Start workers and listen for messages containing notifyRequest - cluster.autoFork(); - Object.keys(cluster.workers).forEach(function(uniqueID) { - cluster.workers[uniqueID].on('message', messageHandler); + var numCPUs = require('os').cpus().length; + for (var i = 0; i < numCPUs; i++) { + cluster.fork(); + } + + Object.keys(cluster.workers).forEach(function(id) { + cluster.workers[id].on('message', messageHandler); }); } else { @@ -434,12 +487,12 @@ on the specified worker. ### Event: 'exit' -* `code` {Number} the exit code, if it exited normally. +* `code` {Number} the exit code, if it exited normally. * `signal` {String} the name of the signal (eg. `'SIGHUP'`) that caused the process to be killed. Emitted by the individual worker instance, when the underlying child process -is terminated. See [child_process event: 'exit'](child_process.html#child_process_event_exit). +is terminated. See [child_process event: 'exit'](child_process.html#child_process_event_exit). var worker = cluster.fork(); worker.on('exit', function(code, signal) { diff --git a/doc/api/crypto.markdown b/doc/api/crypto.markdown index 3537fc13b90..87b9ac37827 100644 --- a/doc/api/crypto.markdown +++ b/doc/api/crypto.markdown @@ -111,16 +111,19 @@ Creates and returns a cipher object, with the given algorithm and password. `algorithm` is dependent on OpenSSL, examples are `'aes192'`, etc. On recent releases, `openssl list-cipher-algorithms` will display the available cipher algorithms. -`password` is used to derive key and IV, which must be `'binary'` encoded -string (See the [Buffer section](buffer.html) for more information). +`password` is used to derive key and IV, which must be a `'binary'` encoded +string or a [buffer](buffer.html). ## crypto.createCipheriv(algorithm, key, iv) Creates and returns a cipher object, with the given algorithm, key and iv. -`algorithm` is the same as the `createCipher()`. `key` is a raw key used in -algorithm. `iv` is an Initialization vector. `key` and `iv` must be `'binary'` -encoded string (See the [Buffer section](buffer.html) for more information). +`algorithm` is the same as the argument to `createCipher()`. +`key` is the raw key used by the algorithm. +`iv` is an [initialization +vector](http://en.wikipedia.org/wiki/Initialization_vector). + +`key` and `iv` must be `'binary'` encoded strings or [buffers](buffer.html). ## Class: Cipher @@ -156,12 +159,12 @@ Useful for non-standard padding, e.g. using `0x0` instead of PKCS padding. You m ## crypto.createDecipher(algorithm, password) Creates and returns a decipher object, with the given algorithm and key. -This is the mirror of the [createCipher()](#crypto.createCipher) above. +This is the mirror of the [createCipher()][] above. ## crypto.createDecipheriv(algorithm, key, iv) Creates and returns a decipher object, with the given algorithm, key and iv. -This is the mirror of the [createCipheriv()](#crypto.createCipheriv) above. +This is the mirror of the [createCipheriv()][] above. ## Class: Decipher @@ -313,13 +316,13 @@ or `'base64'`. Defaults to `'binary'`. Creates a predefined Diffie-Hellman key exchange object. The supported groups are: `'modp1'`, `'modp2'`, `'modp5'` -(defined in [RFC 2412](http://www.rfc-editor.org/rfc/rfc2412.txt )) +(defined in [RFC 2412][]) and `'modp14'`, `'modp15'`, `'modp16'`, `'modp17'`, `'modp18'` -(defined in [RFC 3526](http://www.rfc-editor.org/rfc/rfc3526.txt )). +(defined in [RFC 3526][]). The returned object mimics the interface of objects created by -[crypto.createDiffieHellman()](#crypto.createDiffieHellman) above, but +[crypto.createDiffieHellman()][] above, but will not allow to change the keys (with -[diffieHellman.setPublicKey()](#diffieHellman.setPublicKey) for example). +[diffieHellman.setPublicKey()][] for example). The advantage of using this routine is that the parties don't have to generate nor exchange group modulus beforehand, saving both processor and communication time. @@ -362,3 +365,10 @@ Generates cryptographically strong pseudo-random data. Usage: } catch (ex) { // handle error } + +[createCipher()]: #crypto_crypto_createcipher_algorithm_password +[createCipheriv()]: #crypto_crypto_createcipheriv_algorithm_key_iv +[crypto.createDiffieHellman()]: #crypto_crypto_creatediffiehellman_prime_encoding +[diffieHellman.setPublicKey()]: #crypto_diffiehellman_setpublickey_public_key_encoding +[RFC 2412]: http://www.rfc-editor.org/rfc/rfc2412.txt +[RFC 3526]: http://www.rfc-editor.org/rfc/rfc3526.txt diff --git a/doc/api/domain.markdown b/doc/api/domain.markdown index 5bbdcc33a0a..84b178607b4 100644 --- a/doc/api/domain.markdown +++ b/doc/api/domain.markdown @@ -119,7 +119,7 @@ Returns a new Domain object. The Domain class encapsulates the functionality of routing errors and uncaught exceptions to the active Domain object. -Domain is a child class of EventEmitter. To handle the errors that it +Domain is a child class of [EventEmitter][]. To handle the errors that it catches, listen to its `error` event. ### domain.run(fn) @@ -227,13 +227,16 @@ with a single error handler in a single place. var d = domain.create(); function readSomeFile(filename, cb) { - fs.readFile(filename, d.intercept(function(er, data) { + fs.readFile(filename, d.intercept(function(data) { + // note, the first argument is never passed to the + // callback since it is assumed to be the 'Error' argument + // and thus intercepted by the domain. + // if this throws, it will also be passed to the domain - // additionally, we know that 'er' will always be null, // so the error-handling logic can be moved to the 'error' // event on the domain instead of being repeated throughout // the program. - return cb(er, JSON.parse(data)); + return cb(null, JSON.parse(data)); })); } @@ -255,7 +258,11 @@ The intention of calling `dispose` is generally to prevent cascading errors when a critical part of the Domain context is found to be in an error state. +Once the domain is disposed the `dispose` event will emit. + Note that IO might still be performed. However, to the highest degree possible, once a domain is disposed, further errors from the emitters in that set will be ignored. So, even if some remaining actions are still in flight, Node.js will not communicate further about them. + +[EventEmitter]: events.html#events_class_events_eventemitter diff --git a/doc/api/events.markdown b/doc/api/events.markdown index fed957d3450..b9be5dc5aad 100644 --- a/doc/api/events.markdown +++ b/doc/api/events.markdown @@ -64,6 +64,9 @@ Remove a listener from the listener array for the specified event. Removes all listeners, or those of the specified event. +Note that this will **invalidate** any arrays that have previously been +returned by `emitter.listeners(event)`. + ### emitter.setMaxListeners(n) @@ -75,14 +78,27 @@ that to be increased. Set to zero for unlimited. ### emitter.listeners(event) -Returns an array of listeners for the specified event. This array can be -manipulated, e.g. to remove listeners. +Returns an array of listeners for the specified event. server.on('connection', function (stream) { console.log('someone connected!'); }); console.log(util.inspect(server.listeners('connection'))); // [ [Function] ] +This array **may** be a mutable reference to the same underlying list of +listeners that is used by the event subsystem. However, certain +actions (specifically, removeAllListeners) will invalidate this +reference. + +If you would like to get a copy of the listeners at a specific point in +time that is guaranteed not to change, make a copy, for example by doing +`emitter.listeners(event).slice(0)`. + +In a future release of node, this behavior **may** change to always +return a copy, for consistency. In your programs, please do not rely on +being able to modify the EventEmitter listeners using array methods. +Always use the 'on' method to add new listeners. + ### emitter.emit(event, [arg1], [arg2], [...]) Execute each of the listeners in order with the supplied arguments. diff --git a/doc/api/fs.markdown b/doc/api/fs.markdown index 0554eef5170..4c97a179439 100644 --- a/doc/api/fs.markdown +++ b/doc/api/fs.markdown @@ -130,6 +130,8 @@ Synchronous fchmod(2). Asynchronous lchmod(2). No arguments other than a possible exception are given to the completion callback. +Only available on Mac OS X. + ## fs.lchmodSync(path, mode) Synchronous lchmod(2). @@ -355,13 +357,7 @@ without waiting for the callback. For this scenario, ## fs.writeSync(fd, buffer, offset, length, position) -Synchronous version of buffer-based `fs.write()`. Returns the number of bytes -written. - -## fs.writeSync(fd, str, position, [encoding]) - -Synchronous version of string-based `fs.write()`. `encoding` defaults to -`'utf8'`. Returns the number of _bytes_ written. +Synchronous version of `fs.write()`. Returns the number of bytes written. ## fs.read(fd, buffer, offset, length, position, [callback]) @@ -380,13 +376,7 @@ The callback is given the three arguments, `(err, bytesRead, buffer)`. ## fs.readSync(fd, buffer, offset, length, position) -Synchronous version of buffer-based `fs.read`. Returns the number of -`bytesRead`. - -## fs.readSync(fd, length, position, encoding) - -Legacy synchronous version of string-based `fs.read`. Returns an array with the -data from the file specified and number of bytes read, `[string, bytesRead]`. +Synchronous version of `fs.read`. Returns the number of `bytesRead`. ## fs.readFile(filename, [encoding], [callback]) @@ -456,8 +446,7 @@ The second argument is optional. The `options` if provided should be an object containing two members a boolean, `persistent`, and `interval`. `persistent` indicates whether the process should continue to run as long as files are being watched. `interval` indicates how often the target should be polled, -in milliseconds. (On Linux systems with inotify, `interval` is ignored.) The -default is `{ persistent: true, interval: 0 }`. +in milliseconds. The default is `{ persistent: true, interval: 5007 }`. The `listener` gets two arguments the current stat object and the previous stat object: diff --git a/doc/api/globals.markdown b/doc/api/globals.markdown index d8fb257e7a4..0ca2b0db9d9 100644 --- a/doc/api/globals.markdown +++ b/doc/api/globals.markdown @@ -22,7 +22,7 @@ scope; `var something` inside a Node module will be local to that module. * {Object} -The process object. See the [process object](process.html#process) section. +The process object. See the [process object][] section. ## console @@ -30,7 +30,7 @@ The process object. See the [process object](process.html#process) section. * {Object} -Used to print to stdout and stderr. See the [stdio](stdio.html) section. +Used to print to stdout and stderr. See the [stdio][] section. ## Class: Buffer @@ -38,7 +38,7 @@ Used to print to stdout and stderr. See the [stdio](stdio.html) section. * {Function} -Used to handle binary data. See the [buffer section](buffer.html). +Used to handle binary data. See the [buffer section][] ## require() @@ -46,8 +46,8 @@ Used to handle binary data. See the [buffer section](buffer.html). * {Function} -To require modules. See the [Modules](modules.html#modules) section. -`require` isn't actually a global but rather local to each module. +To require modules. See the [Modules][] section. `require` isn't actually a +global but rather local to each module. ### require.resolve() @@ -123,8 +123,7 @@ A reference to the current module. In particular `module.exports` is the same as the `exports` object. `module` isn't actually a global but rather local to each module. -See the [module system documentation](modules.html) for more -information. +See the [module system documentation][] for more information. ## exports @@ -135,16 +134,51 @@ made accessible through `require()`. `exports` is the same as the `module.exports` object. `exports` isn't actually a global but rather local to each module. -See the [module system documentation](modules.html) for more -information. +See the [module system documentation][] for more information. -See the [module section](modules.html) for more information. +See the [module section][] for more information. ## setTimeout(cb, ms) + +Run callback `cb` after *at least* `ms` milliseconds. The actual delay depends +on external factors like OS timer granularity and system load. + +The timeout must be in the range of 1-2,147,483,647 inclusive. If the value is +outside that range, it's changed to 1 millisecond. Broadly speaking, a timer +cannot span more than 24.8 days. + +Returns an opaque value that represents the timer. + ## clearTimeout(t) + +Stop a timer that was previously created with `setTimeout()`. The callback will +not execute. + ## setInterval(cb, ms) + +Run callback `cb` repeatedly every `ms` milliseconds. Note that the actual +interval may vary, depending on external factors like OS timer granularity and +system load. It's never less than `ms` but it may be longer. + +The interval must be in the range of 1-2,147,483,647 inclusive. If the value is +outside that range, it's changed to 1 millisecond. Broadly speaking, a timer +cannot span more than 24.8 days. + +Returns an opaque value that represents the timer. + ## clearInterval(t) +Stop a timer that was previously created with `setInterval()`. The callback +will not execute. + -The timer functions are global variables. See the [timers](timers.html) section. +The timer functions are global variables. See the [timers][] section. + +[buffer section]: buffer.html +[module section]: modules.html +[module system documentation]: modules.html +[Modules]: modules.html#modules_modules +[process object]: process.html#process_process +[stdio]: stdio.html +[timers]: timers.html diff --git a/doc/api/http.markdown b/doc/api/http.markdown index 962aa49081f..dbd31ac2216 100644 --- a/doc/api/http.markdown +++ b/doc/api/http.markdown @@ -42,13 +42,13 @@ added to the `'request'` event. ## http.createClient([port], [host]) -This function is **deprecated**; please use -[http.request()](#http_http_request_options_callback) instead. Constructs a new -HTTP client. `port` and `host` refer to the server to be connected to. +This function is **deprecated**; please use [http.request()][] instead. +Constructs a new HTTP client. `port` and `host` refer to the server to be +connected to. ## Class: http.Server -This is an `EventEmitter` with the following events: +This is an [EventEmitter][] with the following events: ### Event: 'request' @@ -145,23 +145,38 @@ The actual length will be determined by your OS through sysctl settings such as parameter is 511 (not 512). This function is asynchronous. The last parameter `callback` will be added as -a listener for the ['listening'](net.html#event_listening_) event. -See also [net.Server.listen()](net.html#server.listen). +a listener for the ['listening'][] event. See also [net.Server.listen(port)][]. ### server.listen(path, [callback]) Start a UNIX socket server listening for connections on the given `path`. +This function is asynchronous. The last parameter `callback` will be added as +a listener for the ['listening'][] event. See also [net.Server.listen(path)][]. + + +### server.listen(handle, [listeningListener]) + +* `handle` {Object} +* `listeningListener` {Function} + +The `handle` object can be set to either a server or socket (anything +with an underlying `_handle` member), or a `{fd: }` object. + +This will cause the server to accept connections on the specified +handle, but it is presumed that the file descriptor or handle has +already been bound to a port or domain socket. + +Listening on a file descriptor is not supported on Windows. + This function is asynchronous. The last parameter `callback` will be added as a listener for the ['listening'](net.html#event_listening_) event. See also [net.Server.listen()](net.html#server.listen). - ### server.close([cb]) -Stops the server from accepting new connections. -See [net.Server.close()](net.html#server.close). +Stops the server from accepting new connections. See [net.Server.close()][]. ### server.maxHeadersCount @@ -175,8 +190,8 @@ no limit will be applied. This object is created internally by a HTTP server -- not by the user -- and passed as the first argument to a `'request'` listener. -The request implements the [Readable Stream](stream.html#readable_stream) -interface. This is an `EventEmitter` with the following events: +The request implements the [Readable Stream][] interface. This is an +[EventEmitter][] with the following events: ### Event: 'data' @@ -184,7 +199,7 @@ interface. This is an `EventEmitter` with the following events: Emitted when a piece of the message body is received. The chunk is a string if an encoding has been set with `request.setEncoding()`, otherwise it's a -[Buffer](buffer.html). +[Buffer][]. Note that the __data will be lost__ if there is no listener when a `ServerRequest` emits a `'data'` event. @@ -266,9 +281,8 @@ Also `request.httpVersionMajor` is the first integer and ### request.setEncoding([encoding]) -Set the encoding for the request body. See -[stream.setEncoding()](stream.html#stream_stream_setencoding_encoding) -for more information. +Set the encoding for the request body. See [stream.setEncoding()][] for more +information. ### request.pause() @@ -295,8 +309,8 @@ authentication details. This object is created internally by a HTTP server--not by the user. It is passed as the second parameter to the `'request'` event. -The response implements the [Writable Stream](stream.html#writable_stream) -interface. This is an `EventEmitter` with the following events: +The response implements the [Writable Stream][] interface. This is an +[EventEmitter][] with the following events: ### Event: 'close' @@ -308,8 +322,7 @@ Indicates that the underlaying connection was terminated before ### response.writeContinue() Sends a HTTP/1.1 100 Continue message to the client, indicating that -the request body should be sent. See the [checkContinue](#event_checkContinue_) event on -`Server`. +the request body should be sent. See the ['checkContinue'][] event on `Server`. ### response.writeHead(statusCode, [reasonPhrase], [headers]) @@ -449,7 +462,7 @@ Node maintains several connections per server to make HTTP requests. This function allows one to transparently issue requests. `options` can be an object or a string. If `options` is a string, it is -automatically parsed with [url.parse()](url.html#url.parse). +automatically parsed with [url.parse()][]. Options: @@ -465,10 +478,9 @@ Options: - `headers`: An object containing request headers. - `auth`: Basic authentication i.e. `'user:password'` to compute an Authorization header. -- `agent`: Controls [Agent](#http.Agent) behavior. When an Agent is used - request will default to `Connection: keep-alive`. Possible values: - - `undefined` (default): use [global Agent](#http.globalAgent) for this host - and port. +- `agent`: Controls [Agent][] behavior. When an Agent is used request will + default to `Connection: keep-alive`. Possible values: + - `undefined` (default): use [global Agent][] for this host and port. - `Agent` object: explicitly use the passed in `Agent`. - `false`: opts out of connection pooling with an Agent, defaults request to `Connection: close`. @@ -634,15 +646,15 @@ event, the entire body will be caught. Note: Node does not check whether Content-Length and the length of the body which has been transmitted are equal or not. -The request implements the [Writable Stream](stream.html#writable_stream) -interface. This is an `EventEmitter` with the following events: +The request implements the [Writable Stream][] interface. This is an +[EventEmitter][] with the following events: ### Event 'response' `function (response) { }` -Emitted when a response is received to this request. This event is emitted only once. The -`response` argument will be an instance of `http.ClientResponse`. +Emitted when a response is received to this request. This event is emitted only +once. The `response` argument will be an instance of `http.ClientResponse`. Options: @@ -784,7 +796,7 @@ server--in that case it is suggested to use the `['Transfer-Encoding', 'chunked']` header line when creating the request. -The `chunk` argument should be a [buffer](buffer.html) or a string. +The `chunk` argument should be a [Buffer][] or a string. The `encoding` argument is optional and only applies when `chunk` is a string. Defaults to `'utf8'`. @@ -805,29 +817,26 @@ Aborts a request. (New since v0.3.8.) ### request.setTimeout(timeout, [callback]) -Once a socket is assigned to this request and is connected -[socket.setTimeout(timeout, [callback])](net.html#socket.setTimeout) -will be called. +Once a socket is assigned to this request and is connected +[socket.setTimeout()][] will be called. ### request.setNoDelay([noDelay]) -Once a socket is assigned to this request and is connected -[socket.setNoDelay(noDelay)](net.html#socket.setNoDelay) -will be called. +Once a socket is assigned to this request and is connected +[socket.setNoDelay()][] will be called. ### request.setSocketKeepAlive([enable], [initialDelay]) -Once a socket is assigned to this request and is connected -[socket.setKeepAlive(enable, [initialDelay])](net.html#socket.setKeepAlive) -will be called. +Once a socket is assigned to this request and is connected +[socket.setKeepAlive()][] will be called. ## http.ClientResponse This object is created when making a request with `http.request()`. It is passed to the `'response'` event of the request object. -The response implements the [Readable Stream](stream.html#readable_stream) -interface. This is an `EventEmitter` with the following events: +The response implements the [Readable Stream][] interface. This is an +[EventEmitter][] with the following events: ### Event: 'data' @@ -853,8 +862,7 @@ emitted no other events will be emitted on the response. Indicates that the underlaying connection was terminated before `end` event was emitted. -See [http.ServerRequest](#http.ServerRequest)'s `'close'` event for more -information. +See [http.ServerRequest][]'s `'close'` event for more information. ### response.statusCode @@ -877,9 +885,8 @@ The response trailers object. Only populated after the 'end' event. ### response.setEncoding([encoding]) -Set the encoding for the response body. See -[stream.setEncoding()](stream.html#stream_stream_setencoding_encoding) -for more information. +Set the encoding for the response body. See [stream.setEncoding()][] for more +information. ### response.pause() @@ -888,3 +895,22 @@ Pauses response from emitting events. Useful to throttle back a download. ### response.resume() Resumes a paused response. + +[Agent]: #http_class_http_agent +['checkContinue']: #http_event_checkcontinue +[Buffer]: buffer.html#buffer_buffer +[EventEmitter]: events.html#events_class_events_eventemitter +[global Agent]: #http_http_globalagent +[http.request()]: #http_http_request_options_callback +[http.ServerRequest]: #http_class_http_serverrequest +['listening']: net.html#net_event_listening +[net.Server.close()]: net.html#net_server_close_cb +[net.Server.listen(path)]: net.html#net_server_listen_path_listeninglistener +[net.Server.listen(port)]: net.html#net_server_listen_port_host_backlog_listeninglistener +[Readable Stream]: stream.html#stream_readable_stream +[socket.setKeepAlive()]: net.html#net_socket_setkeepalive_enable_initialdelay +[socket.setNoDelay()]: net.html#net_socket_setnodelay_nodelay +[socket.setTimeout()]: net.html#net_socket_settimeout_timeout_callback +[stream.setEncoding()]: stream.html#stream_stream_setencoding_encoding +[url.parse()]: url.html#url_url_parse_urlstr_parsequerystring_slashesdenotehost +[Writable Stream]: stream.html#stream_writable_stream diff --git a/doc/api/https.markdown b/doc/api/https.markdown index 10c9a3e3ba9..5f0052c2c3a 100644 --- a/doc/api/https.markdown +++ b/doc/api/https.markdown @@ -13,8 +13,8 @@ This class is a subclass of `tls.Server` and emits events same as ## https.createServer(options, [requestListener]) Returns a new HTTPS web server object. The `options` is similar to -[tls.createServer()](tls.html#tls.createServer). The `requestListener` is -a function which is automatically added to the `'request'` event. +[tls.createServer()][]. The `requestListener` is a function which is +automatically added to the `'request'` event. Example: @@ -48,8 +48,8 @@ Or ## https.request(options, callback) -Makes a request to a secure web server. -All options from [http.request()](http.html#http.request) are valid. +Makes a request to a secure web server. All options from [http.request()][] +are valid. Example: @@ -93,16 +93,15 @@ The options argument has the following options - `headers`: An object containing request headers. - `auth`: Basic authentication i.e. `'user:password'` to compute an Authorization header. -- `agent`: Controls [Agent](#https.Agent) behavior. When an Agent is - used request will default to `Connection: keep-alive`. Possible values: - - `undefined` (default): use [globalAgent](#https.globalAgent) for this - host and port. +- `agent`: Controls [Agent][] behavior. When an Agent is used request will + default to `Connection: keep-alive`. Possible values: + - `undefined` (default): use [globalAgent][] for this host and port. - `Agent` object: explicitly use the passed in `Agent`. - `false`: opts out of connection pooling with an Agent, defaults request to `Connection: close`. -The following options from [tls.connect()](tls.html#tls.connect) can also be -specified. However, a [globalAgent](#https.globalAgent) silently ignores these. +The following options from [tls.connect()][] can also be specified. However, a +[globalAgent][] silently ignores these. - `pfx`: Certificate, Private key and CA certificates to use for SSL. Default `null`. - `key`: Private key to use for SSL. Default `null`. @@ -177,11 +176,18 @@ Example: ## Class: https.Agent -An Agent object for HTTPS similar to [http.Agent](http.html#http.Agent). -See [https.request()](#https.request) for more information. +An Agent object for HTTPS similar to [http.Agent][]. See [https.request()][] +for more information. ## https.globalAgent -Global instance of [https.Agent](#https.Agent) which is used as the default -for all HTTPS client requests. +Global instance of [https.Agent][] for all HTTPS client requests. + +[Agent]: #https_class_https_agent +[globalAgent]: #https_https_globalagent +[http.Agent]: http.html#http_class_http_agent +[http.request()]: http.html#http_http_request_options_callback +[https.Agent]: #https_class_https_agent +[tls.connect()]: tls.html#tls_tls_connect_options_secureconnectlistener +[tls.createServer()]: tls.html#tls_tls_createserver_options_secureconnectionlistener diff --git a/doc/api/modules.markdown b/doc/api/modules.markdown index d90cf578739..4720aa5ece1 100644 --- a/doc/api/modules.markdown +++ b/doc/api/modules.markdown @@ -383,7 +383,7 @@ Additionally, node will search in the following locations: * 3: `$PREFIX/lib/node` Where `$HOME` is the user's home directory, and `$PREFIX` is node's -configured `installPrefix`. +configured `node_prefix`. These are mostly for historic reasons. You are highly encouraged to place your dependencies locally in `node_modules` folders. They will be diff --git a/doc/api/net.markdown b/doc/api/net.markdown index 7fb07df9558..6d4e2382ae0 100644 --- a/doc/api/net.markdown +++ b/doc/api/net.markdown @@ -9,8 +9,7 @@ this module with `require('net');` ## net.createServer([options], [connectionListener]) Creates a new TCP server. The `connectionListener` argument is -automatically set as a listener for the ['connection'](#event_connection_) -event. +automatically set as a listener for the ['connection'][] event. `options` is an object with the following defaults: @@ -20,7 +19,7 @@ event. If `allowHalfOpen` is `true`, then the socket won't automatically send a FIN packet when the other end of the socket sends a FIN packet. The socket becomes non-readable, but still writable. You should call the `end()` method explicitly. -See ['end'](#event_end_) event for more information. +See ['end'][] event for more information. Here is an example of a echo server which listens for connections on port 8124: @@ -55,8 +54,7 @@ Use `nc` to connect to a UNIX domain socket server: ## net.createConnection(options, [connectionListener]) Constructs a new socket object and opens the socket to the given location. -When the socket is established, the ['connect'](#event_connect_) event will be -emitted. +When the socket is established, the ['connect'][] event will be emitted. For TCP sockets, `options` argument should be an object which specifies: @@ -74,11 +72,10 @@ Common options are: - `allowHalfOpen`: if `true`, the socket won't automatically send a FIN packet when the other end of the socket sends a FIN packet. - Defaults to `false`. - See ['end'](#event_end_) event for more information. + Defaults to `false`. See ['end'][] event for more information. The `connectListener` parameter will be added as an listener for the -['connect'](#event_connect_) event. +['connect'][] event. Here is an example of a client of echo server as described previously: @@ -107,14 +104,14 @@ changed to Creates a TCP connection to `port` on `host`. If `host` is omitted, `'localhost'` will be assumed. The `connectListener` parameter will be added as an listener for the -['connect'](#event_connect_) event. +['connect'][] event. ## net.connect(path, [connectListener]) ## net.createConnection(path, [connectListener]) Creates unix socket connection to `path`. The `connectListener` parameter will be added as an listener for the -['connect'](#event_connect_) event. +['connect'][] event. ## Class: net.Server @@ -133,9 +130,8 @@ The actual length will be determined by your OS through sysctl settings such as parameter is 511 (not 512). This function is asynchronous. When the server has been bound, -['listening'](#event_listening_) event will be emitted. -the last parameter `listeningListener` will be added as an listener for the -['listening'](#event_listening_) event. +['listening'][] event will be emitted. The last parameter `listeningListener` +will be added as an listener for the ['listening'][] event. One issue some users run into is getting `EADDRINUSE` errors. This means that another server is already running on the requested port. One way of handling this @@ -158,6 +154,24 @@ would be to wait a second and then try again. This can be done with Start a UNIX socket server listening for connections on the given `path`. +This function is asynchronous. When the server has been bound, +['listening'][] event will be emitted. The last parameter `listeningListener` +will be added as an listener for the ['listening'][] event. + +### server.listen(handle, [listeningListener]) + +* `handle` {Object} +* `listeningListener` {Function} + +The `handle` object can be set to either a server or socket (anything +with an underlying `_handle` member), or a `{fd: }` object. + +This will cause the server to accept connections on the specified +handle, but it is presumed that the file descriptor or handle has +already been bound to a port or domain socket. + +Listening on a file descriptor is not supported on Windows. + This function is asynchronous. When the server has been bound, ['listening'](#event_listening_) event will be emitted. the last parameter `listeningListener` will be added as an listener for the @@ -207,7 +221,7 @@ The number of concurrent connections on the server. This becomes `null` when sending a socket to a child with `child_process.fork()`. -`net.Server` is an `EventEmitter` with the following events: +`net.Server` is an [EventEmitter][] with the following events: ### Event: 'listening' @@ -266,13 +280,12 @@ Normally this method is not needed, as `net.createConnection` opens the socket. Use this only if you are implementing a custom Socket or if a Socket is closed and you want to reuse it to connect to another server. -This function is asynchronous. When the ['connect'](#event_connect_) event is -emitted the socket is established. If there is a problem connecting, the -`'connect'` event will not be emitted, the `'error'` event will be emitted with -the exception. +This function is asynchronous. When the ['connect'][] event is emitted the +socket is established. If there is a problem connecting, the `'connect'` event +will not be emitted, the `'error'` event will be emitted with the exception. The `connectListener` parameter will be added as an listener for the -['connect'](#event_connect_) event. +['connect'][] event. ### socket.bufferSize @@ -297,8 +310,7 @@ Users who experience large or growing `bufferSize` should attempt to ### socket.setEncoding([encoding]) Set the encoding for the socket as a Readable Stream. See -[stream.setEncoding()](stream.html#stream_stream_setencoding_encoding) -for more information. +[stream.setEncoding()][] for more information. ### socket.write(data, [encoding], [callback]) @@ -392,7 +404,7 @@ The amount of received bytes. The amount of bytes sent. -`net.Socket` instances are EventEmitters with the following events: +`net.Socket` instances are [EventEmitter][] with the following events: ### Event: 'connect' @@ -405,8 +417,7 @@ See `connect()`. Emitted when data is received. The argument `data` will be a `Buffer` or `String`. Encoding of data is set by `socket.setEncoding()`. -(See the [Readable Stream](stream.html#readable_stream) section for more -information.) +(See the [Readable Stream][] section for more information.) Note that the __data will be lost__ if there is no listener when a `Socket` emits a `'data'` event. @@ -465,3 +476,10 @@ Returns true if input is a version 4 IP address, otherwise returns false. Returns true if input is a version 6 IP address, otherwise returns false. +['connect']: #net_event_connect +['connection']: #net_event_connection +['end']: #net_event_end +[EventEmitter]: events.html#events_class_events_eventemitter +['listening']: #net_event_listening +[Readable Stream]: stream.html#stream_readable_stream +[stream.setEncoding()]: stream.html#stream_stream_setencoding_encoding diff --git a/doc/api/os.markdown b/doc/api/os.markdown index 33eb9b6317d..b5fffcf1cb4 100644 --- a/doc/api/os.markdown +++ b/doc/api/os.markdown @@ -6,6 +6,10 @@ Provides a few basic operating-system related utility functions. Use `require('os')` to access this module. +## os.tmpDir() + +Returns the operating system's default directory for temp files. + ## os.hostname() Returns the hostname of the operating system. diff --git a/doc/api/process.markdown b/doc/api/process.markdown index 21eda7d551f..35b104dfabd 100644 --- a/doc/api/process.markdown +++ b/doc/api/process.markdown @@ -3,7 +3,7 @@ The `process` object is a global object and can be accessed from anywhere. -It is an instance of `EventEmitter`. +It is an instance of [EventEmitter][]. ## Event: 'exit' @@ -295,18 +295,11 @@ An example of the possible output looks like: node_shared_zlib: 'false', node_use_dtrace: 'false', node_use_openssl: 'true', - node_use_system_openssl: 'false', + node_shared_openssl: 'false', strict_aliasing: 'true', target_arch: 'x64', v8_use_snapshot: 'true' } } -## process.installPrefix - -A compiled-in property that exposes `NODE_PREFIX`. - - console.log('Prefix: ' + process.installPrefix); - - ## process.kill(pid, [signal]) Send a signal to a process. `pid` is the process id and `signal` is the @@ -425,3 +418,5 @@ a diff reading, useful for benchmarks and measuring intervals: console.log('benchmark took %d seconds and %d nanoseconds', t[0], t[1]); // benchmark took 1 seconds and 6962306 nanoseconds }, 1000); + +[EventEmitter]: events.html#events_class_events_eventemitter diff --git a/doc/api/stdio.markdown b/doc/api/stdio.markdown index a70dcefa160..0da30a0add0 100644 --- a/doc/api/stdio.markdown +++ b/doc/api/stdio.markdown @@ -17,8 +17,7 @@ Prints to stdout with newline. This function can take multiple arguments in a console.log('count: %d', count); If formatting elements are not found in the first string then `util.inspect` -is used on each argument. -See [util.format()](util.html#util.format) for more information. +is used on each argument. See [util.format()][] for more information. ## console.info([data], [...]) @@ -56,6 +55,8 @@ Print a stack trace to stderr of the current position. ## console.assert(expression, [message]) -Same as [assert.ok()](assert.html#assert_assert_value_message_assert_ok_value_message) -where if the `expression` evaluates as `false` throw an AssertionError with `message`. +Same as [assert.ok()][] where if the `expression` evaluates as `false` throw an +AssertionError with `message`. +[assert.ok()]: assert.html#assert_assert_value_message_assert_ok_value_message +[util.format()]: util.html#util_util_format_format diff --git a/doc/api/stream.markdown b/doc/api/stream.markdown index 72d9c9c95a1..66160df63a0 100644 --- a/doc/api/stream.markdown +++ b/doc/api/stream.markdown @@ -4,7 +4,7 @@ A stream is an abstract interface implemented by various objects in Node. For example a request to an HTTP server is a stream, as is stdout. Streams -are readable, writable, or both. All streams are instances of `EventEmitter`. +are readable, writable, or both. All streams are instances of [EventEmitter][] You can load up the Stream base class by doing `require('stream')`. @@ -182,3 +182,5 @@ Any queued write data will not be sent. After the write queue is drained, close the file descriptor. `destroySoon()` can still destroy straight away, as long as there is no data left in the queue for writes. + +[EventEmitter]: events.html#events_class_events_eventemitter diff --git a/doc/api/tls.markdown b/doc/api/tls.markdown index f5283c3f954..279a672faa1 100644 --- a/doc/api/tls.markdown +++ b/doc/api/tls.markdown @@ -49,8 +49,8 @@ server-side resources, which makes it a potential vector for denial-of-service attacks. To mitigate this, renegotiations are limited to three times every 10 minutes. An -error is emitted on the [CleartextStream](#tls.CleartextStream) instance when -the threshold is exceeded. The limits are configurable: +error is emitted on the [CleartextStream][] instance when the threshold is +exceeded. The limits are configurable: - `tls.CLIENT_RENEG_LIMIT`: renegotiation limit, default is 3. @@ -78,10 +78,9 @@ handshake extensions allowing you: ## tls.createServer(options, [secureConnectionListener]) -Creates a new [tls.Server](#tls.Server). -The `connectionListener` argument is automatically set as a listener for the -[secureConnection](#event_secureConnection_) event. -The `options` object has these possibilities: +Creates a new [tls.Server][]. The `connectionListener` argument is +automatically set as a listener for the [secureConnection][] event. The +`options` object has these possibilities: - `pfx`: A string or `Buffer` containing the private key, certificate and CA certs of the server in PFX or PKCS12 format. (Mutually exclusive with @@ -241,9 +240,9 @@ Creates a new client connection to the given `port` and `host` (old API) or - `servername`: Servername for SNI (Server Name Indication) TLS extension. The `secureConnectListener` parameter will be added as a listener for the -['secureConnect'](#event_secureConnect_) event. +['secureConnect'][] event. -`tls.connect()` returns a [CleartextStream](#tls.CleartextStream) object. +`tls.connect()` returns a [CleartextStream][] object. Here is an example of a client of echo server as described previously: @@ -315,8 +314,8 @@ and the cleartext one is used as a replacement for the initial encrypted stream. automatically reject clients with invalid certificates. Only applies to servers with `requestCert` enabled. -`tls.createSecurePair()` returns a SecurePair object with -[cleartext](#tls.CleartextStream) and `encrypted` stream properties. +`tls.createSecurePair()` returns a SecurePair object with [cleartext][] and +`encrypted` stream properties. ## Class: SecurePair @@ -342,9 +341,8 @@ connections using TLS or SSL. `function (cleartextStream) {}` This event is emitted after a new connection has been successfully -handshaked. The argument is a instance of -[CleartextStream](#tls.CleartextStream). It has all the common stream methods -and events. +handshaked. The argument is a instance of [CleartextStream][]. It has all the +common stream methods and events. `cleartextStream.authorized` is a boolean value which indicates if the client has verified by one of the supplied certificate authorities for the @@ -386,8 +384,8 @@ event. ### server.address() Returns the bound address, the address family name and port of the -server as reported by the operating system. -See [net.Server.address()](net.html#server.address) for more information. +server as reported by the operating system. See [net.Server.address()][] for +more information. ### server.addContext(hostname, credentials) @@ -410,8 +408,8 @@ The number of concurrent connections on the server. This is a stream on top of the *Encrypted* stream that makes it possible to read/write an encrypted data as a cleartext data. -This instance implements a duplex [Stream](stream.html) interfaces. -It has all the common stream methods and events. +This instance implements a duplex [Stream][] interfaces. It has all the +common stream methods and events. A ClearTextStream is the `clear` member of a SecurePair object. @@ -489,3 +487,10 @@ The string representation of the remote IP address. For example, ### cleartextStream.remotePort The numeric representation of the remote port. For example, `443`. + +[CleartextStream]: #tls_class_tls_cleartextstream +[net.Server.address()]: net.html#net_server_address +['secureConnect']: #tls_event_secureconnect +[secureConnection]: #tls_event_secureconnection +[Stream]: stream.html#stream_stream +[tls.Server]: #tls_class_tls_server diff --git a/doc/api/zlib.markdown b/doc/api/zlib.markdown index a4c3a93ef34..66c92846029 100644 --- a/doc/api/zlib.markdown +++ b/doc/api/zlib.markdown @@ -103,15 +103,6 @@ tradeoffs involved in zlib usage. } }).listen(1337); -## Constants - - - -All of the constants defined in zlib.h are also defined on -`require('zlib')`. They are described in more detail in the zlib -documentation. See -for more details. - ## zlib.createGzip([options]) Returns a new [Gzip](#zlib_class_zlib_gzip) object with an @@ -232,8 +223,8 @@ relevant when compressing, and are ignored by the decompression classes. * strategy (compression only) * dictionary (deflate/inflate only, empty dictionary by default) -See the description of `deflateInit2` and `inflateInit2` at - for more information on these. +See the description of `deflateInit2` and `inflateInit2` +at for more information on these. ## Memory Usage Tuning @@ -274,3 +265,69 @@ In general, greater memory usage options will mean that node has to make fewer calls to zlib, since it'll be able to process more data in a single `write` operation. So, this is another factor that affects the speed, at the cost of memory usage. + +## Constants + + + +All of the constants defined in zlib.h are also defined on +`require('zlib')`. +In the normal course of operations, you will not need to ever set any of +these. They are documented here so that their presence is not +surprising. This section is taken almost directly from the [zlib +documentation](http://zlib.net/manual.html#Constants). See + for more details. + +Allowed flush values. + +* `zlib.Z_NO_FLUSH` +* `zlib.Z_PARTIAL_FLUSH` +* `zlib.Z_SYNC_FLUSH` +* `zlib.Z_FULL_FLUSH` +* `zlib.Z_FINISH` +* `zlib.Z_BLOCK` +* `zlib.Z_TREES` + +Return codes for the compression/decompression functions. Negative +values are errors, positive values are used for special but normal +events. + +* `zlib.Z_OK` +* `zlib.Z_STREAM_END` +* `zlib.Z_NEED_DICT` +* `zlib.Z_ERRNO` +* `zlib.Z_STREAM_ERROR` +* `zlib.Z_DATA_ERROR` +* `zlib.Z_MEM_ERROR` +* `zlib.Z_BUF_ERROR` +* `zlib.Z_VERSION_ERROR` + +Compression levels. + +* `zlib.Z_NO_COMPRESSION` +* `zlib.Z_BEST_SPEED` +* `zlib.Z_BEST_COMPRESSION` +* `zlib.Z_DEFAULT_COMPRESSION` + +Compression strategy. + +* `zlib.Z_FILTERED` +* `zlib.Z_HUFFMAN_ONLY` +* `zlib.Z_RLE` +* `zlib.Z_FIXED` +* `zlib.Z_DEFAULT_STRATEGY` + +Possible values of the data_type field. + +* `zlib.Z_BINARY` +* `zlib.Z_TEXT` +* `zlib.Z_ASCII` +* `zlib.Z_UNKNOWN` + +The deflate compression method (the only one supported in this version). + +* `zlib.Z_DEFLATED` + +For initializing zalloc, zfree, opaque. + +* `zlib.Z_NULL` diff --git a/doc/blog.html b/doc/blog.html new file mode 100644 index 00000000000..6d55b8fe9cc --- /dev/null +++ b/doc/blog.html @@ -0,0 +1,240 @@ + + + + + + + + + + <%= title || "Node.js Blog" %> + + + + +
+ +
+ +
+
+ + + +
+ +
+

<%- title %>

+ <% if (typeof post !== 'undefined') { + // just one post on this page + %> +

<%- + post.date.toUTCString().replace(/ GMT$/, '') + ' UTC' + + (post.author ? ' - ' + post.author : '') + + (post.category ? ' - ' + + post.category + '' : '') + %>

+ + <%- post.content %> + +

Please post feedback and comments on + the Node.JS + user mailing list.
+ Please post bugs and feature requests on + the Node.JS + github repository.

+ + <% + if (post.next || post.prev) { + if (post.prev) { + %>

← <%= + post.prev.title + %>

+ <% + } + if (post.next) { + %>

<%= + post.next.title + %> →

+ <% + } + } + } else { // not single post page + if (paginated && total > 1 ) { + if (page > 0) { + // add 1 to all of the displayed numbers, because + // humans are not zero-indexed like they ought to be. + %> +

+ ← Page <%- page %> +

+ <% + } + if (page < total - 1) { %> +

+ Page <%- page + 2 %> → +

+ <% + } + } + + posts.forEach(function(post) { + %> +
+

+ +

<%- + post.date.toUTCString().replace(/ GMT$/, '') + ' UTC' + + (post.author ? ' - ' + post.author : '') + + (post.category ? ' - ' + + post.category + '' : '') + %>

+ + <%- post.content %> +
+ <% + }); + + if (paginated && total > 1 ) { + if (page > 0) { + // add 1 to all of the displayed numbers, because + // humans are not zero-indexed like they ought to be. + %> +

+ ← Page <%- page %> +

+ <% + } + if (page < total - 1) { %> +

+ Page <%- page + 2 %> → +

+ <% + } + } // pagination + } // not a single post + %> +
+
+ + + + + + + + + diff --git a/doc/blog/README.md b/doc/blog/README.md new file mode 100644 index 00000000000..7d37706470a --- /dev/null +++ b/doc/blog/README.md @@ -0,0 +1,28 @@ +title: README.md +status: private + +# How This Blog Works + +Each `.md` file in this folder structure is a blog post. It has a +few headers and a markdown body. (HTML is allowed in the body as well.) + +The relevant headers are: + +1. title +2. author +3. status: Only posts with a status of "publish" are published. +4. category: The "release" category is treated a bit specially. +5. version: Only relevant for "release" category. +6. date +7. slug: The bit that goes on the url. Must be unique, will be + generated from the title and date if missing. + +Posts in the "release" category are only shown in the main lists when +they are the most recent release for that version family. The stable +branch supercedes its unstable counterpart, so the presence of a `0.8.2` +release notice will cause `0.7.10` to be hidden, but `0.6.19` would +be unaffected. + +The folder structure in the blog source does not matter. Organize files +here however makes sense. The metadata will be sorted out in the build +later. diff --git a/doc/blog/Uncategorized/an-easy-way-to-build-scalable-network-programs.md b/doc/blog/Uncategorized/an-easy-way-to-build-scalable-network-programs.md new file mode 100644 index 00000000000..e1a509ecd78 --- /dev/null +++ b/doc/blog/Uncategorized/an-easy-way-to-build-scalable-network-programs.md @@ -0,0 +1,16 @@ +title: An Easy Way to Build Scalable Network Programs +author: ryandahl +date: Tue Oct 04 2011 15:39:56 GMT-0700 (PDT) +status: publish +category: Uncategorized +slug: an-easy-way-to-build-scalable-network-programs + +Suppose you're writing a web server which does video encoding on each file upload. Video encoding is very much compute bound. Some recent blog posts suggest that Node.js would fail miserably at this. + +Using Node does not mean that you have to write a video encoding algorithm in JavaScript (a language without even 64 bit integers) and crunch away in the main server event loop. The suggested approach is to separate the I/O bound task of receiving uploads and serving downloads from the compute bound task of video encoding. In the case of video encoding this is accomplished by forking out to ffmpeg. Node provides advanced means of asynchronously controlling subprocesses for work like this. + +It has also been suggested that Node does not take advantage of multicore machines. Node has long supported load-balancing connections over multiple processes in just a few lines of code - in this way a Node server will use the available cores. In coming releases we'll make it even easier: just pass --balance on the command line and Node will manage the cluster of processes. + +Node has a clear purpose: provide an easy way to build scalable network programs. It is not a tool for every problem. Do not write a ray tracer with Node. Do not write a web browser with Node. Do however reach for Node if tasked with writing a DNS server, DHCP server, or even a video encoding server. + +By relying on the kernel to schedule and preempt computationally expensive tasks and to load balance incoming connections, Node appears less magical than server platforms that employ userland scheduling. So far, our focus on simplicity and transparency has paid off: the number of success stories from developers and corporations who are adopting the technology continues to grow. diff --git a/doc/blog/Uncategorized/development-environment.md b/doc/blog/Uncategorized/development-environment.md new file mode 100644 index 00000000000..f7141815890 --- /dev/null +++ b/doc/blog/Uncategorized/development-environment.md @@ -0,0 +1,25 @@ +title: Development Environment +author: ryandahl +date: Mon Apr 04 2011 20:16:27 GMT-0700 (PDT) +status: publish +category: Uncategorized +slug: development-environment + +If you're compiling a software package because you need a particular version (e.g. the latest), then it requires a little bit more maintenance than using a package manager like dpkg. Software that you compile yourself should *not* go into /usr, it should go into your home directory. This is part of being a software developer. + +One way of doing this is to install everything into $HOME/local/$PACKAGE. Here is how I install node on my machine:
./configure --prefix=$HOME/local/node-v0.4.5 && make install
+ +To have my paths automatically set I put this inside my $HOME/.zshrc:
PATH="$HOME/local/bin:/opt/local/bin:/usr/bin:/sbin:/bin"
+LD_LIBRARY_PATH="/opt/local/lib:/usr/local/lib:/usr/lib"
+for i in $HOME/local/*; do
+  [ -d $i/bin ] && PATH="${i}/bin:${PATH}"
+  [ -d $i/sbin ] && PATH="${i}/sbin:${PATH}"
+  [ -d $i/include ] && CPATH="${i}/include:${CPATH}"
+  [ -d $i/lib ] && LD_LIBRARY_PATH="${i}/lib:${LD_LIBRARY_PATH}"
+  [ -d $i/lib/pkgconfig ] && PKG_CONFIG_PATH="${i}/lib/pkgconfig:${PKG_CONFIG_PATH}"
+  [ -d $i/share/man ] && MANPATH="${i}/share/man:${MANPATH}"
+done
+ +Node is under sufficiently rapid development that everyone should be compiling it themselves. A corollary of this is that npm (which should be installed alongside Node) does not require root to install packages. + +CPAN and RubyGems have blurred the lines between development tools and system package managers. With npm we wish to draw a clear line: it is not a system package manager. It is not for installing firefox or ffmpeg or OpenSSL; it is for rapidly downloading, building, and setting up Node packages. npm is a development tool. When a program written in Node becomes sufficiently mature it should be distributed as a tarball, .deb, .rpm, or other package system. It should not be distributed to end users with npm. diff --git a/doc/blog/Uncategorized/evolving-the-node-js-brand.md b/doc/blog/Uncategorized/evolving-the-node-js-brand.md new file mode 100644 index 00000000000..dbb7f852f15 --- /dev/null +++ b/doc/blog/Uncategorized/evolving-the-node-js-brand.md @@ -0,0 +1,34 @@ +title: Evolving the Node.js Brand +author: Emily Tanaka-Delgado +date: Mon Jul 11 2011 12:02:45 GMT-0700 (PDT) +status: publish +category: Uncategorized +slug: evolving-the-node-js-brand + +To echo Node’s evolutionary nature, we have refreshed the identity to help mark an exciting time for developers, businesses and users who benefit from the pioneering technology. + +Building a brand + +We began exploring elements to express Node.js and jettisoned preconceived notions about what we thought Node should look like, and focused on what Node is: kinetic,connectedscalablemodularmechanical and organic. Working with designer Chris Glass, our explorations emphasized Node's dynamism and formed a visual language based on structure, relationships and interconnectedness. + + + +Inspired by process visualization, we discovered pattern, form, and by relief, the hex shape. The angled infrastructure encourages energy to move through the letterforms. + + + +This language can expand into the organic network topography of Node or distill down into a single hex connection point. + +This scaling represents the dynamic nature of Node in a simple, distinct manner. + + + +We look forward to exploring this visual language as the technology charges into a very promising future. + + + +We hope you'll have fun using it. + +To download the new logo, visit nodejs.org/logos. + + diff --git a/doc/blog/Uncategorized/growing-up.md b/doc/blog/Uncategorized/growing-up.md new file mode 100644 index 00000000000..6faff59cec7 --- /dev/null +++ b/doc/blog/Uncategorized/growing-up.md @@ -0,0 +1,12 @@ +title: Growing up +author: ryandahl +date: Thu Dec 15 2011 11:59:15 GMT-0800 (PST) +status: publish +category: Uncategorized +slug: growing-up + +This week Microsoft announced support for Node in Windows Azure, their cloud computing platform. For the Node core team and the community, this is an important milestone. We've worked hard over the past six months reworking Node's machinery to support IO completion ports and Visual Studio to provide a good native port to Windows. The overarching goal of the port was to expand our user base to the largest number of developers. Happily, this has paid off in the form of being a first class citizen on Azure. Many users who would have never used Node as a pure unix tool are now up and running on the Windows platform. More users translates into a deeper and better ecosystem of modules, which makes for a better experience for everyone. + +We also redesigned our website - something that we've put off for a long time because we felt that Node was too nascent to dedicate marketing to it. But now that we have binary distributions for Macintosh and Windows, have bundled npm, and are serving millions of users at various companies, we felt ready to indulge in a new website and share of a few of our success stories on the home page. + +Work is on-going. We continue to improve the software, making performance improvements and adding isolate support, but Node is growing up. diff --git a/doc/blog/Uncategorized/jobs-nodejs-org.md b/doc/blog/Uncategorized/jobs-nodejs-org.md new file mode 100644 index 00000000000..bf8278b816c --- /dev/null +++ b/doc/blog/Uncategorized/jobs-nodejs-org.md @@ -0,0 +1,14 @@ +title: jobs.nodejs.org +author: ryandahl +date: Thu Mar 24 2011 23:05:22 GMT-0700 (PDT) +status: publish +category: Uncategorized +slug: jobs-nodejs-org + +We are starting an official jobs board for Node. There are two goals for this + +1. Promote the small emerging economy around this platform by having a central space for employers to find Node programmers. + +2. Make some money. We work hard to build this platform and taking a small tax for job posts seems a like reasonable "tip jar". + +jobs.nodejs.org diff --git a/doc/blog/Uncategorized/ldapjs-a-reprise-of-ldap.md b/doc/blog/Uncategorized/ldapjs-a-reprise-of-ldap.md new file mode 100644 index 00000000000..57d4af7fe13 --- /dev/null +++ b/doc/blog/Uncategorized/ldapjs-a-reprise-of-ldap.md @@ -0,0 +1,84 @@ +title: ldapjs: A reprise of LDAP +author: mcavage +date: Thu Sep 08 2011 14:25:43 GMT-0700 (PDT) +status: publish +category: Uncategorized +slug: ldapjs-a-reprise-of-ldap + +This post has been about 10 years in the making. My first job out of college was at IBM working on the Tivoli Directory Server, and at the time I had a preconceived notion that working on anything related to Internet RFCs was about as hot as you could get. I spent a lot of time back then getting "down and dirty" with everything about LDAP: the protocol, performance, storage engines, indexing and querying, caching, customer use cases and patterns, general network server patterns, etc. Basically, I soaked up as much as I possibly could while I was there. On top of that, I listened to all the "gray beards" tell me about the history of LDAP, which was a bizarre marriage of telecommunications conglomerates and graduate students. The point of this blog post is to give you a crash course in LDAP, and explain what makes ldapjs different. Allow me to be the gray beard for a bit... +

What is LDAP and where did it come from?

+ +Directory services were largely pioneered by the telecommunications companies (e.g., AT&T) to allow fast information retrieval of all the crap you'd expect would be in a telephone book and directory. That is, given a name, or an address, or an area code, or a number, or a foo support looking up customer records, billing information, routing information, etc. The efforts of several telcos came to exist in the X.500 standard(s). An X.500 directory is one of the most complicated beasts you can possibly imagine, but on a high note, there's +probably not a thing you can imagine in a directory service that wasn't thought of in there. It is literally the kitchen sink. Oh, and it doesn't run over IP (it's actually on the OSI model). + +Several years after X.500 had been deployed (at telcos, academic institutions, etc.), it became clear that the Internet was "for real." LDAP, the "Lightweight Directory Access Protocol," was invented to act purely as an IP-accessible gateway to an X.500 directory. + +At some point in the early 90's, a graduate student at the University of Michigan (with some help) cooked up the "grandfather" implementation of the LDAP protocol, which wasn't actually a "gateway," but rather a stand-alone implementation of LDAP. Said implementation, like many things at the time, was a process-per-connection concurrency model, and had "backends" (aka storage engine) for the file system and the Unix DB API. At some point the Berkeley Database (BDB) was put in, and still remains the de facto storage engine for most LDAP directories. + +Ok, so some a graduate student at UM wrote an LDAP server that wasn't a gateway. So what? Well, that UM code base turns out to be the thing that pretty much every vendor did a source license for. Those graduate students went off to Netscape later in the 90's, and largely dominated the market of LDAP middleware until Active Directory came along many years later (as far as I know, Active Directory is "from scratch", since while it's "almost" LDAP, it's different in a lot of ways). That Netscape code base was further bought and sold over the years to iPlanet, Sun Microsystems, and Red Hat (I'm probably missing somebody in that chain). It now lives in the Fedora umbrella as '389 Directory Server.' Probably the most popular fork of that code base now is OpenLDAP. + +IBM did the same thing, and the Directory Server I worked on was a fork of the UM code too, but it heavily diverged from the Netscape branches. The divergence was primarily due to: (1) backing to DB2 as opposed to BDB, and (2) needing to run on IBM's big iron like OS/400 and Z series mainframes. + +Macro point is that there have actually been very few "fresh" implementations of LDAP, and it gets a pretty bad reputation because at the end of the day you've got 20 years of "bolt-ons" to grad student code. Oh, and it was born out of ginormous telcos, so of course the protocol is overly complex. + +That said, while there certainly is some wacky stuff in the LDAP protocol itself, it really suffered from poor and buggy implementations more than the fact that LDAP itself was fundamentally flawed. As engine yard pointed out a few years back, you can think of LDAP as the original NoSQL store. +

LDAP: The Good Parts

+ +So what's awesome about LDAP? Since it's a directory system it maintains a hierarchy of your data, which as an information management pattern aligns +with _a lot_ of use case (the quintessential example is white pages for people in your company, but subscriptions to SaaS applications, "host groups" +for tracking machines/instances, physical goods tracking, etc., all have use cases that fit that organization scheme). For example, presumably at your job +you have a "reporting chain." Let's say a given record in LDAP (I'll use myself as a guinea pig here) looks like: +
    firstName: Mark
+    lastName: Cavage
+    city: Seattle
+    uid: markc
+    state: Washington
+    mail: mcavagegmailcom
+    phone: (206) 555-1212
+    title: Software Engineer
+    department: 123456
+    objectclass: joyentPerson
+The record for me would live under the tree of engineers I report to (and as an example some other popular engineers under said vice president) would look like: +
                   uid=david
+                    /
+               uid=bryan
+            /      |      \
+      uid=markc  uid=ryah  uid=isaacs
+Ok, so we've got a tree. It's not tremendously different from your filesystem, but how do we find people? LDAP has a rich search filter syntax that makes a lot of sense for key/value data (far more than tacking Map Reduce jobs on does, imo), and all search queries take a "start point" in the tree. Here's an example: let's say I wanted to find all "Software Engineers" in the entire company, a filter would look like: +
     (title="Software Engineer")
+And I'd just start my search from 'uid=david' in the example above. Let's say I wanted to find all software engineers who worked in Seattle: +
     (&(title="Software Engineer")(city=Seattle))
+I could keep going, but the gist is that LDAP has "full" boolean predicate logic, wildcard filters, etc. It's really rich. + +Oh, and on top of the technical merits, better or worse, it's an established standard for both administrators and applications (i.e., most "shipped" intranet software has either a local user repository or the ability to leverage an LDAP server somewhere). So there's a lot of compelling reasons to look at leveraging LDAP. +

ldapjs: Why do I care?

+ +As I said earlier, I spent a lot of time at IBM observing how customers used LDAP, and the real items I took away from that experience were: +
    +
  • LDAP implementations have suffered a lot from never having been designed from the ground up for a large number of concurrent connections with asynchronous operations.
  • +
  • There are use cases for LDAP that just don't always fit the traditional "here's my server and storage engine" model. A lot of simple customer use cases wanted an LDAP access point, but not be forced into taking the heavy backends that came with it (they wanted the original gateway model!). There was an entire "sub" industry for this known as "meta directories" back in the late 90's and early 2000's.
  • +
  • Replication was always a sticking point. LDAP vendors all tried to offer a big multi-master, multi-site replication model. It was a lot of "bolt-on" complexity, done before the CAP theorem was written, and certainly before it was accepted as "truth."
  • +
  • Nobody uses all of the protocol. In fact, 20% of the features solve 80% of the use cases (I'm making that number up, but you get the idea).
  • +
+ +For all the good parts of LDAP, those are really damned big failing points, and even I eventually abandoned LDAP for the greener pastures of NoSQL somewhere +along the way. But it always nagged at me that LDAP didn't get it's due because of a lot of implementation problems (to be clear, if I could, I'd change some +aspects of the protocol itself too, but that's a lot harder). + +Well, in the last year, I went to work for Joyent, and like everyone else, we have several use problems that are classic directory service problems. If you break down the list I outlined above: +
    +
  • Connection-oriented and asynchronous: Holy smokes batman, node.js is a completely kick-ass event-driven asynchronous server platform that manages connections like a boss. Check!
  • +
  • Lots of use cases: Yeah, we've got some. Man, the sinatra/express paradigm is so easy to slap over anything. How about we just do that and leave as many use cases open as we can. Check!
  • +
  • Replication is hard. CAP is right: There are a lot of distributed databases out vying to solve exactly this problem. At Joyent we went with Riak. Check!
  • +
  • Don't need all of the protocol: I'm lazy. Let's just skip the stupid things most people don't need. Check!
  • +
+ +So that's the crux of ldapjs right there. Giving you the ability to put LDAP back into your application while nailing those 4 fundamental problems that plague most existing LDAP deployments. + +The obvious question is how it turned out, and the answer is, honestly, better than I thought it would. When I set out to do this, I actually assumed I'd be shipping a much smaller percentage of the RFC than is there. There's actually about 95% of the core RFC implemented. I wasn't sure if the marriage of this protocol to node/JavaScript would work out, but if you've used express ever, this should be _really_ familiar. And I tried to make it as natural as possible to use "pure" JavaScript objects, rather than requiring the developer to understand ASN.1 (the binary wire protocol) or the LDAP RFC in detail (this one mostly worked out; ldap_modify is still kind of a PITA). + +Within 24 hours of releasing ldapjs on Twitter, there was an implementation of an address book that works with Thunderbird/Evolution, by the end of that weekend there was some slick integration with CouchDB, and ldapjs even got used in one of the node knockout apps. Off to a pretty good start! + +

The Road Ahead

+ +Hopefully you've been motivated to learn a little bit more about LDAP and try out ldapjs. The best place to start is probably the guide. After that you'll probably need to pick up a book from back in the day. ldapjs itself is still in its infancy; there's quite a bit of room to add some slick client-side logic (e.g., connection pools, automatic reconnects), easy to use schema validation, backends, etc. By the time this post is live, there will be experimental dtrace support if you're running on Mac OS X or preferably Joyent's SmartOS (shameless plug). And that nagging percentage of the protocol I didn't do will get filled in over time I suspect. If you've got an interest in any of this, send me some pull requests, but most importantly, I just want to see LDAP not just be a skeleton in the closet and get used in places where you should be using it. So get out there and write you some LDAP. diff --git a/doc/blog/Uncategorized/libuv-status-report.md b/doc/blog/Uncategorized/libuv-status-report.md new file mode 100644 index 00000000000..68637a43b92 --- /dev/null +++ b/doc/blog/Uncategorized/libuv-status-report.md @@ -0,0 +1,45 @@ +title: libuv status report +author: ryandahl +date: Fri Sep 23 2011 12:45:50 GMT-0700 (PDT) +status: publish +category: Uncategorized +slug: libuv-status-report + +We announced back in July that with Microsoft's support Joyent would be porting Node to Windows. This effort is ongoing but I thought it would be nice to make a status report post about the new platform library libuv which has resulted from porting Node to Windows. + +libuv's purpose is to abstract platform-dependent code in Node into one place where it can be tested for correctness and performance before bindings to V8 are added. Since Node is totally non-blocking, libuv turns out to be a rather useful library itself: a BSD-licensed, minimal, high-performance, cross-platform networking library. + +We attempt to not reinvent the wheel where possible. The entire Unix backend sits heavily on Marc Lehmann's beautiful libraries libev and libeio. For DNS we integrated with Daniel Stenberg's C-Ares. For cross-platform build-system support we're relying on Chrome's GYP meta-build system. + +The current implmented features are: +
    +
  • Non-blocking TCP sockets (using IOCP on Windows)
  • +
  • Non-blocking named pipes
  • +
  • UDP
  • +
  • Timers
  • +
  • Child process spawning
  • +
  • Asynchronous DNS via c-ares or uv_getaddrinfo.
  • +
  • Asynchronous file system APIs uv_fs_*
  • +
  • High resolution time uv_hrtime
  • +
  • Current executable path look up uv_exepath
  • +
  • Thread pool scheduling uv_queue_work
  • +
+The features we are working on still are +
    +
  • File system events (Currently supports inotify, ReadDirectoryChangesW and will support kqueue and event ports in the near future.) uv_fs_event_t
  • +
  • VT100 TTY uv_tty_t
  • +
  • Socket sharing between processes uv_ipc_t (planned API)
  • +
+For complete documentation see the header file: include/uv.h. There are a number of tests in the test directory which demonstrate the API. + +libuv supports Microsoft Windows operating systems since Windows XP SP2. It can be built with either Visual Studio or MinGW. Solaris 121 and later using GCC toolchain. Linux 2.6 or better using the GCC toolchain. Macinotsh Darwin using the GCC or XCode toolchain. It is known to work on the BSDs but we do not check the build regularly. + +In addition to Node v0.5, a number of projects have begun to use libuv: + +We hope to see more people contributing and using libuv in the future! diff --git a/doc/blog/Uncategorized/node-meetup-this-thursday.md b/doc/blog/Uncategorized/node-meetup-this-thursday.md new file mode 100644 index 00000000000..0dfb98dae50 --- /dev/null +++ b/doc/blog/Uncategorized/node-meetup-this-thursday.md @@ -0,0 +1,11 @@ +title: Node Meetup this Thursday +author: ryandahl +date: Tue Aug 02 2011 21:37:02 GMT-0700 (PDT) +status: publish +category: Uncategorized +slug: node-meetup-this-thursday + +http://nodejs.org/meetup/ +http://nodemeetup.eventbrite.com/ + +Three companies will describe their distributed Node applications. Sign up soon, space is limited! diff --git a/doc/blog/Uncategorized/node-office-hours-cut-short.md b/doc/blog/Uncategorized/node-office-hours-cut-short.md new file mode 100644 index 00000000000..48d0344057a --- /dev/null +++ b/doc/blog/Uncategorized/node-office-hours-cut-short.md @@ -0,0 +1,12 @@ +title: Node Office Hours Cut Short +author: ryandahl +date: Thu Apr 28 2011 09:04:35 GMT-0700 (PDT) +status: publish +category: Uncategorized +slug: node-office-hours-cut-short + +This week office hours are only from 4pm to 6pm. Isaac will be in the Joyent office in SF - everyone else is out of town. Sign up at http://nodeworkup.eventbrite.com/ if you would like to come. + +The week after, Thursday May 5th, we will all be at NodeConf in Portland. + +Normal office hours resume Thursday May 12th. diff --git a/doc/blog/Uncategorized/office-hours.md b/doc/blog/Uncategorized/office-hours.md new file mode 100644 index 00000000000..e4c94992ce7 --- /dev/null +++ b/doc/blog/Uncategorized/office-hours.md @@ -0,0 +1,12 @@ +title: Office Hours +author: ryandahl +date: Wed Mar 23 2011 21:42:47 GMT-0700 (PDT) +status: publish +category: Uncategorized +slug: office-hours + +Starting next Thursday Isaac, Tom, and I will be holding weekly office hours at Joyent HQ in San Francisco. Office hours are meant to be subdued working time - there are no talks and no alcohol. Bring your bugs or just come and hack with us. + +Our building requires that everyone attending be on a list so you must sign up at Event Brite. + +We start at 4p and end promptly at 8p. diff --git a/doc/blog/Uncategorized/porting-node-to-windows-with-microsoft%e2%80%99s-help.md b/doc/blog/Uncategorized/porting-node-to-windows-with-microsoft%e2%80%99s-help.md new file mode 100644 index 00000000000..d2be3e3ba2a --- /dev/null +++ b/doc/blog/Uncategorized/porting-node-to-windows-with-microsoft%e2%80%99s-help.md @@ -0,0 +1,12 @@ +title: Porting Node to Windows With Microsoft’s Help +author: ryandahl +date: Thu Jun 23 2011 15:22:58 GMT-0700 (PDT) +status: publish +category: Uncategorized +slug: porting-node-to-windows-with-microsoft%e2%80%99s-help + +I'm pleased to announce that Microsoft is partnering with Joyent in formally contributing resources towards porting Node to Windows. As you may have heard in a talk we gave earlier this year, we have started the undertaking of a native port to Windows - targeting the high-performance IOCP API. + +This requires a rather large modification of the core structure, and we're very happy to have official guidance and engineering resources from Microsoft. Rackspace is also contributing Bert Belder's time to this undertaking. + +The result will be an official binary node.exe releases on nodejs.org, which will work on Windows Azure and other Windows versions as far back as Server 2003. diff --git a/doc/blog/Uncategorized/profiling-node-js.md b/doc/blog/Uncategorized/profiling-node-js.md new file mode 100644 index 00000000000..ff259c3c42c --- /dev/null +++ b/doc/blog/Uncategorized/profiling-node-js.md @@ -0,0 +1,60 @@ +title: Profiling Node.js +author: Dave Pacheco +date: Wed Apr 25 2012 13:48:58 GMT-0700 (PDT) +status: publish +category: Uncategorized +slug: profiling-node-js + +It's incredibly easy to visualize where your Node program spends its time using DTrace and node-stackvis (a Node port of Brendan Gregg's FlameGraph tool): + +
    +
  1. Run your Node.js program as usual.
  2. +
  3. In another terminal, run: +
    +$ dtrace -o stacks.out -n 'profile-97/execname == "node" && arg1/{
    +    @[jstack(100, 8000)] = count(); } tick-60s { exit(0); }'
    + This will sample about 100 times per second for 60 seconds and emit results to stacks.out. Note that this will sample all running programs called "node". If you want a specific process, replace execname == "node" with pid == 12345 (the process id). +
  4. +
  5. Use the "stackvis" tool to transform this directly into a flame graph. First, install it: +
    $ npm install -g stackvis
    + then use stackvis to convert the DTrace output to a flamegraph: +
    $ stackvis dtrace flamegraph-svg < stacks.out > stacks.svg
    +
  6. +
  7. Open stacks.svg in your favorite browser.
  8. +
+ +You'll be looking at something like this: + + + +This is a visualization of all of the profiled call stacks. This example is from the "hello world" HTTP server on the Node.js home page under load. Start at the bottom, where you have "main", which is present in most Node stacks because Node spends most on-CPU time in the main thread. Above each row, you have the functions called by the frame beneath it. As you move up, you'll see actual JavaScript function names. The boxes in each row are not in chronological order, but their width indicates how much time was spent there. When you hover over each box, you can see exactly what percentage of time is spent in each function. This lets you see at a glance where your program spends its time. + +That's the summary. There are a few prerequisites: + +
    +
  • You must gather data on a system that supports DTrace with the Node.js ustack helper. For now, this pretty much means illumos-based systems like SmartOS, including the Joyent Cloud. MacOS users: OS X supports DTrace, but not ustack helpers. The way to get this changed is to contact your Apple developer liason (if you're lucky enough to have one) or file a bug report at bugreport.apple.com. I'd suggest referencing existing bugs 5273057 and 11206497. More bugs filed (even if closed as dups) show more interest and make it more likely Apple will choose to fix this.
  • +
  • You must be on 32-bit Node.js 0.6.7 or later, built --with-dtrace. The helper doesn't work with 64-bit Node yet. On illumos (including SmartOS), development releases (the 0.7.x train) include DTrace support by default.
  • +
+ +There are a few other notes: + +
    +
  • You can absolutely profile apps in production, not just development, since compiling with DTrace support has very minimal overhead. You can start and stop profiling without restarting your program.
  • +
  • You may want to run the stacks.out output through c++filt to demangle C++ symbols. Be sure to use the c++filt that came with the compiler you used to build Node. For example: +
    c++filt < stacks.out > demangled.out
    + then you can use demangled.out to create the flamegraph. +
  • +
  • If you want, you can filter stacks containing a particular function. The best way to do this is to first collapse the original DTrace output, then grep out what you want: +
    +$ stackvis dtrace collapsed < stacks.out | grep SomeFunction > collapsed.out
    +$ stackvis collapsed flamegraph-svg < collapsed.out > stacks.svg
    +
  • +
  • If you've used Brendan's FlameGraph tools, you'll notice the coloring is a little different in the above flamegraph. I ported his tools to Node first so I could incorporate it more easily into other Node programs, but I've also been playing with different coloring options. The current default uses hue to denote stack depth and saturation to indicate time spent. (These are also indicated by position and size.) Other ideas include coloring by module (so V8, JavaScript, libc, etc. show up as different colors.) +
  • +
+ +For more on the underlying pieces, see my previous post on Node.js profiling and Brendan's post on Flame Graphs. + +
+ +Dave Pacheco blogs at dtrace.org diff --git a/doc/blog/Uncategorized/some-new-node-projects.md b/doc/blog/Uncategorized/some-new-node-projects.md new file mode 100644 index 00000000000..77515af7364 --- /dev/null +++ b/doc/blog/Uncategorized/some-new-node-projects.md @@ -0,0 +1,13 @@ +title: Some New Node Projects +author: ryandahl +date: Mon Aug 29 2011 08:30:41 GMT-0700 (PDT) +status: publish +category: Uncategorized +slug: some-new-node-projects + +
    +
  • Superfeedr released a Node XMPP Server. "Since astro had been doing an amazing work with his node-xmpp library to build Client, Components and even Server to server modules, the logical next step was to try to build a Client to Server module so that we could have a full blown server. That’s what we worked on the past couple days, and it’s now on Github!
  • + +
  • Joyent's Mark Cavage released LDAP.js. "ldapjs is a pure JavaScript, from-scratch framework for implementing LDAP clients and servers in Node.js. It is intended for developers used to interacting with HTTP services in node and express.
  • + +
  • Microsoft's Tomasz Janczuk released iisnode "The iisnode project provides a native IIS 7.x module that allows hosting of node.js applications in IIS.

    Scott Hanselman posted a detailed walkthrough of how to get started with iisnode diff --git a/doc/blog/Uncategorized/the-videos-from-node-meetup.md b/doc/blog/Uncategorized/the-videos-from-node-meetup.md new file mode 100644 index 00000000000..aa2ce5ac564 --- /dev/null +++ b/doc/blog/Uncategorized/the-videos-from-node-meetup.md @@ -0,0 +1,10 @@ +title: The Videos from the Meetup +author: ryandahl +date: Fri Aug 12 2011 00:14:34 GMT-0700 (PDT) +status: publish +category: Uncategorized +slug: the-videos-from-node-meetup + +Uber, Voxer, and Joyent described how they use Node in production + +http://joyeur.com/2011/08/11/node-js-meetup-distributed-web-architectures/ diff --git a/doc/blog/Uncategorized/trademark.md b/doc/blog/Uncategorized/trademark.md new file mode 100644 index 00000000000..fc89cfa044d --- /dev/null +++ b/doc/blog/Uncategorized/trademark.md @@ -0,0 +1,17 @@ +title: Trademark +author: ryandahl +date: Fri Apr 29 2011 01:54:18 GMT-0700 (PDT) +status: publish +category: Uncategorized +slug: trademark + +One of the things Joyent accepted when we took on the Node project was to provide resources to help the community grow. The Node project is amazing because of the expertize, dedication and hard work of the community. However in all communities there is the possibility of people acting inappropriately. We decided to introduce trademarks on the “Node.js” and the “Node logo” in order to ensure that people or organisations who are not investing in the Node community misrepresent, or create confusion about the role of themselves or their products with Node. + +We are big fans of the people who have contributed to Node and we have worked hard to make sure that existing members of the community will be unaffected by this change. For most people they don’t have to do anything they are free to use the Node.js marks in their free open source projects (see guidelines). For others we’ve already granted them licenses to use Node.js marks in their domain names and their businesses. We value all of these contributions to the Node community and hope that we can continue to protect their good names and hard work. + +Where does our trademark policy come from? We started by looking at popular open source foundations like the Apache Software Foundation and Linux. By strongly basing our policy on the one used by the Apache Software Foundation we feel that we’ve created a policy which is liberal enough to allow the open source community to easily make use of the mark in the context of free open source software, but secure enough to protect the community’s work from being misrepresented by other organisations. + +While we realise that any changes involving lawyers can be intimidating to the community we want to make this transition as smoothly as possible and welcome your questions and feedback on the policy and how we are implementing it. + +http://nodejs.org/trademark-policy.pdf +trademark@joyent.com diff --git a/doc/blog/Uncategorized/version-0-6.md b/doc/blog/Uncategorized/version-0-6.md new file mode 100644 index 00000000000..9ab82985f97 --- /dev/null +++ b/doc/blog/Uncategorized/version-0-6.md @@ -0,0 +1,12 @@ +title: Version 0.6 Coming Soon +author: ryandahl +date: Tue Oct 25 2011 15:26:23 GMT-0700 (PDT) +status: publish +category: Uncategorized +slug: version-0-6 + +Version 0.6.0 will be released next week. Please spend some time this week upgrading your code to v0.5.10. Report any API differences at https://github.com/joyent/node/wiki/API-changes-between-v0.4-and-v0.6 or report a bug to us at http://github.com/joyent/node/issues if you hit problems. + +The API changes between v0.4.12 and v0.5.10 are 99% cosmetic, minor, and easy to fix. Most people are able to migrate their code in 10 minutes. Don't fear. + +Once you've ported your code to v0.5.10 please help out by testing third party modules. Make bug reports. Encourage authors to publish new versions of their modules. Go through the list of modules at http://search.npmjs.org/ and try out random ones. This is especially encouraged of Windows users! diff --git a/doc/blog/module/multi-server-continuous-deployment-with-fleet.md b/doc/blog/module/multi-server-continuous-deployment-with-fleet.md new file mode 100644 index 00000000000..7d76ad894cb --- /dev/null +++ b/doc/blog/module/multi-server-continuous-deployment-with-fleet.md @@ -0,0 +1,89 @@ +title: multi-server continuous deployment with fleet +author: Isaac Schlueter +date: Wed May 02 2012 11:00:00 GMT-0700 (PDT) +status: publish +category: module +slug: multi-server-continuous-deployment-with-fleet + +

    substackThis is a guest post by James "SubStack" Halliday, originally posted on his blog, and reposted here with permission.

    + +

    Writing applications as a sequence of tiny services that all talk to each other over the network has many upsides, but it can be annoyingly tedious to get all the subsystems up and running.

    + +

    Running a seaport can help with getting all the services to talk to each other, but running the processes is another matter, especially when you have new code to push into production.

    + +

    fleet aims to make it really easy for anyone on your team to push new code from git to an armada of servers and manage all the processes in your stack.

    + +

    To start using fleet, just install the fleet command with npm:

    + +
    npm install -g fleet 
    + +

    Then on one of your servers, start a fleet hub. From a fresh directory, give it a passphrase and a port to listen on:

    + +
    fleet hub --port=7000 --secret=beepboop 
    + +

    Now fleet is listening on :7000 for commands and has started a git server on :7001 over http. There's no ssh keys or post commit hooks to configure, just run that command and you're ready to go!

    + +

    Next set up some worker drones to run your processes. You can have as many workers as you like on a single server but each worker should be run from a separate directory. Just do:

    + +
    fleet drone --hub=x.x.x.x:7000 --secret=beepboop 
    + +

    where x.x.x.x is the address where the fleet hub is running. Spin up a few of these drones.

    + +

    Now navigate to the directory of the app you want to deploy. First set a remote so you don't need to type --hub and --secret all the time.

    + +
    fleet remote add default --hub=x.x.x.x:7000 --secret=beepboop 
    + +

    Fleet just created a fleet.json file for you to save your settings.

    + +

    From the same app directory, to deploy your code just do:

    + +
    fleet deploy 
    + +

    The deploy command does a git push to the fleet hub's git http server and then the hub instructs all the drones to pull from it. Your code gets checked out into a new directory on all the fleet drones every time you deploy.

    + +

    Because fleet is designed specifically for managing applications with lots of tiny services, the deploy command isn't tied to running any processes. Starting processes is up to the programmer but it's super simple. Just use the fleet spawn command:

    + +
    fleet spawn -- node server.js 8080 
    + +

    By default fleet picks a drone at random to run the process on. You can specify which drone you want to run a particular process on with the --drone switch if it matters.

    + +

    Start a few processes across all your worker drones and then show what is running with the fleet ps command:

    + +
    fleet ps
    +drone#3dfe17b8
    +├─┬ pid#1e99f4
    +│ ├── status:   running
    +│ ├── commit:   webapp/1b8050fcaf8f1b02b9175fcb422644cb67dc8cc5
    +│ └── command:  node server.js 8888
    +└─┬ pid#d7048a
    +  ├── status:   running
    +  ├── commit:   webapp/1b8050fcaf8f1b02b9175fcb422644cb67dc8cc5
    +  └── command:  node server.js 8889
    + +

    Now suppose that you have new code to push out into production. By default, fleet lets you spin up new services without disturbing your existing services. If you fleet deploy again after checking in some new changes to git, the next time you fleet spawn a new process, that process will be spun up in a completely new directory based on the git commit hash. To stop a process, just use fleet stop.

    + +

    This approach lets you verify that the new services work before bringing down the old services. You can even start experimenting with heterogeneous and incremental deployment by hooking into a custom http proxy!

    + +

    Even better, if you use a service registry like seaport for managing the host/port tables, you can spin up new ad-hoc staging clusters all the time without disrupting the normal operation of your site before rolling out new code to users.

    + +

    Fleet has many more commands that you can learn about with its git-style manpage-based help system! Just do fleet help to get a list of all the commands you can run.

    + +
    fleet help
    +Usage: fleet <command> [<args>]
    +
    +The commands are:
    +  deploy   Push code to drones.
    +  drone    Connect to a hub as a worker.
    +  exec     Run commands on drones.
    +  hub      Create a hub for drones to connect.
    +  monitor  Show service events system-wide.
    +  ps       List the running processes on the drones.
    +  remote   Manage the set of remote hubs.
    +  spawn    Run services on drones.
    +  stop     Stop processes running on drones.
    +
    +For help about a command, try `fleet help `.
    + +

    npm install -g fleet and check out the code on github!

    + + diff --git a/doc/blog/module/service-logging-in-json-with-bunyan.md b/doc/blog/module/service-logging-in-json-with-bunyan.md new file mode 100644 index 00000000000..2a6891e7dc5 --- /dev/null +++ b/doc/blog/module/service-logging-in-json-with-bunyan.md @@ -0,0 +1,337 @@ +title: Service logging in JSON with Bunyan +author: trentmick +date: Wed Mar 28 2012 12:25:26 GMT-0700 (PDT) +status: publish +category: module +slug: service-logging-in-json-with-bunyan + + + +

    Service logs are gold, if you can mine them. We scan them for occasional debugging. Perhaps we grep them looking for errors or warnings, or setup an occasional nagios log regex monitor. If that. This is a waste of the best channel for data about a service.

    + +

    "Log. (Huh) What is it good for. Absolutely ..."

    + +
      +
    • debugging
    • +
    • monitors tools that alert operators
    • +
    • non real-time analysis (business or operational analysis)
    • +
    • historical analysis
    • +
    + +

    These are what logs are good for. The current state of logging is barely adequate for the first of these. Doing reliable analysis, and even monitoring, of varied "printf-style" logs is a grueling or hacky task that most either don't bother with, fallback to paying someone else to do (viz. Splunk's great successes), or, for web sites, punt and use the plethora of JavaScript-based web analytics tools.

    + +

    Let's log in JSON. Let's format log records with a filter outside the app. Let's put more info in log records by not shoehorning into a printf-message. Debuggability can be improved. Monitoring and analysis can definitely be improved. Let's not write another regex-based parser, and use the time we've saved writing tools to collate logs from multiple nodes and services, to query structured logs (from all services, not just web servers), etc.

    + +

    At Joyent we use node.js for running many core services -- loosely coupled through HTTP REST APIs and/or AMQP. In this post I'll draw on experiences from my work on Joyent's SmartDataCenter product and observations of Joyent Cloud operations to suggest some improvements to service logging. I'll show the (open source) Bunyan logging library and tool that we're developing to improve the logging toolchain.

    + +

    Current State of Log Formatting

    + +
    # apache access log
    +10.0.1.22 - - [15/Oct/2010:11:46:46 -0700] "GET /favicon.ico HTTP/1.1" 404 209
    +fe80::6233:4bff:fe29:3173 - - [15/Oct/2010:11:46:58 -0700] "GET / HTTP/1.1" 200 44
    +
    +# apache error log
    +[Fri Oct 15 11:46:46 2010] [error] [client 10.0.1.22] File does not exist: /Library/WebServer/Documents/favicon.ico
    +[Fri Oct 15 11:46:58 2010] [error] [client fe80::6233:4bff:fe29:3173] File does not exist: /Library/WebServer/Documents/favicon.ico
    +
    +# Mac /var/log/secure.log
    +Oct 14 09:20:56 banana loginwindow[41]: in pam_sm_authenticate(): Failed to determine Kerberos principal name.
    +Oct 14 12:32:20 banana com.apple.SecurityServer[25]: UID 501 authenticated as user trentm (UID 501) for right 'system.privilege.admin'
    +
    +# an internal joyent agent log
    +[2012-02-07 00:37:11.898] [INFO] AMQPAgent - Publishing success.
    +[2012-02-07 00:37:11.910] [DEBUG] AMQPAgent - { req_id: '8afb8d99-df8e-4724-8535-3d52adaebf25',
    +  timestamp: '2012-02-07T00:37:11.898Z',
    +
    +# typical expressjs log output
    +[Mon, 21 Nov 2011 20:52:11 GMT] 200 GET /foo (1ms)
    +Blah, some other unstructured output to from a console.log call.
    +
    + +

    What're we doing here? Five logs at random. Five different date formats. As Paul Querna points out we haven't improved log parsability in 20 years. Parsability is enemy number one. You can't use your logs until you can parse the records, and faced with the above the inevitable solution is a one-off regular expression.

    + +

    The current state of the art is various parsing libs, analysis tools and homebrew scripts ranging from grep to Perl, whose scope is limited to a few niches log formats.

    + +

    JSON for Logs

    + +

    JSON.parse() solves all that. Let's log in JSON. But it means a change in thinking: The first-level audience for log files shouldn't be a person, but a machine.

    + +

    That is not said lightly. The "Unix Way" of small focused tools lightly coupled with text output is important. JSON is less "text-y" than, e.g., Apache common log format. JSON makes grep and awk awkward. Using less directly on a log is handy.

    + +

    But not handy enough. That 80's pastel jumpsuit awkwardness you're feeling isn't the JSON, it's your tools. Time to find a json tool -- json is one, bunyan described below is another one. Time to learn your JSON library instead of your regex library: JavaScript, Python, Ruby, Java, Perl.

    + +

    Time to burn your log4j Layout classes and move formatting to the tools side. Creating a log message with semantic information and throwing that away to make a string is silly. The win at being able to trivially parse log records is huge. The possibilities at being able to add ad hoc structured information to individual log records is interesting: think program state metrics, think feeding to Splunk, or loggly, think easy audit logs.

    + +

    Introducing Bunyan

    + +

    Bunyan is a node.js module for logging in JSON and a bunyan CLI tool to view those logs.

    + +

    Logging with Bunyan basically looks like this:

    + +
    $ cat hi.js
    +var Logger = require('bunyan');
    +var log = new Logger({name: 'hello' /*, ... */});
    +log.info("hi %s", "paul");
    +
    + +

    And you'll get a log record like this:

    + +
    $ node hi.js
    +{"name":"hello","hostname":"banana.local","pid":40026,"level":30,"msg":"hi paul","time":"2012-03-28T17:25:37.050Z","v":0}
    +
    + +

    Pipe that through the bunyan tool that is part of the "node-bunyan" install to get more readable output:

    + +
    $ node hi.js | ./node_modules/.bin/bunyan       # formatted text output
    +[2012-02-07T18:50:18.003Z]  INFO: hello/40026 on banana.local: hi paul
    +
    +$ node hi.js | ./node_modules/.bin/bunyan -j    # indented JSON output
    +{
    +  "name": "hello",
    +  "hostname": "banana.local",
    +  "pid": 40087,
    +  "level": 30,
    +  "msg": "hi paul",
    +  "time": "2012-03-28T17:26:38.431Z",
    +  "v": 0
    +}
    +
    + +

    Bunyan is log4j-like: create a Logger with a name, call log.info(...), etc. However it has no intention of reproducing much of the functionality of log4j. IMO, much of that is overkill for the types of services you'll tend to be writing with node.js.

    + +

    Longer Bunyan Example

    + +

    Let's walk through a bigger example to show some interesting things in Bunyan. We'll create a very small "Hello API" server using the excellent restify library -- which we used heavily here at Joyent. (Bunyan doesn't require restify at all, you can easily use Bunyan with Express or whatever.)

    + +

    You can follow along in https://github.com/trentm/hello-json-logging if you like. Note that I'm using the current HEAD of the bunyan and restify trees here, so details might change a bit. Prerequisite: a node 0.6.x installation.

    + +
    git clone https://github.com/trentm/hello-json-logging.git
    +cd hello-json-logging
    +make
    +
    + +

    Bunyan Logger

    + +

    Our server first creates a Bunyan logger:

    + +
    var Logger = require('bunyan');
    +var log = new Logger({
    +  name: 'helloapi',
    +  streams: [
    +    {
    +      stream: process.stdout,
    +      level: 'debug'
    +    },
    +    {
    +      path: 'hello.log',
    +      level: 'trace'
    +    }
    +  ],
    +  serializers: {
    +    req: Logger.stdSerializers.req,
    +    res: restify.bunyan.serializers.response,
    +  },
    +});
    +
    + +

    Every Bunyan logger must have a name. Unlike log4j, this is not a hierarchical dotted namespace. It is just a name field for the log records.

    + +

    Every Bunyan logger has one or more streams, to which log records are written. Here we've defined two: logging at DEBUG level and above is written to stdout, and logging at TRACE and above is appended to 'hello.log'.

    + +

    Bunyan has the concept of serializers: a registry of functions that know how to convert a JavaScript object for a certain log record field to a nice JSON representation for logging. For example, here we register the Logger.stdSerializers.req function to convert HTTP Request objects (using the field name "req") to JSON. More on serializers later.

    + +

    Restify Server

    + +

    Restify 1.x and above has bunyan support baked in. You pass in your Bunyan logger like this:

    + +
    var server = restify.createServer({
    +  name: 'Hello API',
    +  log: log   // Pass our logger to restify.
    +});
    +
    + +

    Our simple API will have a single GET /hello?name=NAME endpoint:

    + +
    server.get({path: '/hello', name: 'SayHello'}, function(req, res, next) {
    +  var caller = req.params.name || 'caller';
    +  req.log.debug('caller is "%s"', caller);
    +  res.send({"hello": caller});
    +  return next();
    +});
    +
    + +

    If we run that, node server.js, and call the endpoint, we get the expected restify response:

    + +
    $ curl -iSs http://0.0.0.0:8080/hello?name=paul
    +HTTP/1.1 200 OK
    +Access-Control-Allow-Origin: *
    +Access-Control-Allow-Headers: Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version
    +Access-Control-Expose-Headers: X-Api-Version, X-Request-Id, X-Response-Time
    +Server: Hello API
    +X-Request-Id: f6aaf942-c60d-4c72-8ddd-bada459db5e3
    +Access-Control-Allow-Methods: GET
    +Connection: close
    +Content-Length: 16
    +Content-MD5: Xmn3QcFXaIaKw9RPUARGBA==
    +Content-Type: application/json
    +Date: Tue, 07 Feb 2012 19:12:35 GMT
    +X-Response-Time: 4
    +
    +{"hello":"paul"}
    +
    + +

    Setup Server Logging

    + +

    Let's add two things to our server. First, we'll use the server.pre to hook into restify's request handling before routing where we'll log the request.

    + +
    server.pre(function (request, response, next) {
    +  request.log.info({req: request}, 'start');        // (1)
    +  return next();
    +});
    +
    + +

    This is the first time we've seen this log.info style with an object as the first argument. Bunyan logging methods (log.trace, log.debug, ...) all support an optional first object argument with extra log record fields:

    + +
    log.info(<object> fields, <string> msg, ...)
    +
    + +

    Here we pass in the restify Request object, req. The "req" serializer we registered above will come into play here, but bear with me.

    + +

    Remember that we already had this debug log statement in our endpoint handler:

    + +
    req.log.debug('caller is "%s"', caller);            // (2)
    +
    + +

    Second, use the restify server after event to log the response:

    + +
    server.on('after', function (req, res, route) {
    +  req.log.info({res: res}, "finished");             // (3)
    +});
    +
    + +

    Log Output

    + +

    Now lets see what log output we get when somebody hits our API's endpoint:

    + +
    $ curl -iSs http://0.0.0.0:8080/hello?name=paul
    +HTTP/1.1 200 OK
    +...
    +X-Request-Id: 9496dfdd-4ec7-4b59-aae7-3fed57aed5ba
    +...
    +
    +{"hello":"paul"}
    +
    + +

    Here is the server log:

    + +
    [trentm@banana:~/tm/hello-json-logging]$ node server.js
    +... intro "listening at" log message elided ...
    +{"name":"helloapi","hostname":"banana.local","pid":40341,"level":30,"req":{"method":"GET","url":"/hello?name=paul","headers":{"user-agent":"curl/7.19.7 (universal-apple-darwin10.0) libcurl/7.19.7 OpenSSL/0.9.8r zlib/1.2.3","host":"0.0.0.0:8080","accept":"*/*"},"remoteAddress":"127.0.0.1","remotePort":59831},"msg":"start","time":"2012-03-28T17:37:29.506Z","v":0}
    +{"name":"helloapi","hostname":"banana.local","pid":40341,"route":"SayHello","req_id":"9496dfdd-4ec7-4b59-aae7-3fed57aed5ba","level":20,"msg":"caller is \"paul\"","time":"2012-03-28T17:37:29.507Z","v":0}
    +{"name":"helloapi","hostname":"banana.local","pid":40341,"route":"SayHello","req_id":"9496dfdd-4ec7-4b59-aae7-3fed57aed5ba","level":30,"res":{"statusCode":200,"headers":{"access-control-allow-origin":"*","access-control-allow-headers":"Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version","access-control-expose-headers":"X-Api-Version, X-Request-Id, X-Response-Time","server":"Hello API","x-request-id":"9496dfdd-4ec7-4b59-aae7-3fed57aed5ba","access-control-allow-methods":"GET","connection":"close","content-length":16,"content-md5":"Xmn3QcFXaIaKw9RPUARGBA==","content-type":"application/json","date":"Wed, 28 Mar 2012 17:37:29 GMT","x-response-time":3}},"msg":"finished","time":"2012-03-28T17:37:29.510Z","v":0}
    +
    + +

    Lets look at each in turn to see what is interesting -- pretty-printed with node server.js | ./node_modules/.bin/bunyan -j:

    + +
    {                                                   // (1)
    +  "name": "helloapi",
    +  "hostname": "banana.local",
    +  "pid": 40442,
    +  "level": 30,
    +  "req": {
    +    "method": "GET",
    +    "url": "/hello?name=paul",
    +    "headers": {
    +      "user-agent": "curl/7.19.7 (universal-apple-darwin10.0) libcurl/7.19.7 OpenSSL/0.9.8r zlib/1.2.3",
    +      "host": "0.0.0.0:8080",
    +      "accept": "*/*"
    +    },
    +    "remoteAddress": "127.0.0.1",
    +    "remotePort": 59834
    +  },
    +  "msg": "start",
    +  "time": "2012-03-28T17:39:44.880Z",
    +  "v": 0
    +}
    +
    + +

    Here we logged the incoming request with request.log.info({req: request}, 'start'). The use of the "req" field triggers the "req" serializer registered at Logger creation.

    + +

    Next the req.log.debug in our handler:

    + +
    {                                                   // (2)
    +  "name": "helloapi",
    +  "hostname": "banana.local",
    +  "pid": 40442,
    +  "route": "SayHello",
    +  "req_id": "9496dfdd-4ec7-4b59-aae7-3fed57aed5ba",
    +  "level": 20,
    +  "msg": "caller is \"paul\"",
    +  "time": "2012-03-28T17:39:44.883Z",
    +  "v": 0
    +}
    +
    + +

    and the log of response in the "after" event:

    + +
    {                                                   // (3)
    +  "name": "helloapi",
    +  "hostname": "banana.local",
    +  "pid": 40442,
    +  "route": "SayHello",
    +  "req_id": "9496dfdd-4ec7-4b59-aae7-3fed57aed5ba",
    +  "level": 30,
    +  "res": {
    +    "statusCode": 200,
    +    "headers": {
    +      "access-control-allow-origin": "*",
    +      "access-control-allow-headers": "Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version",
    +      "access-control-expose-headers": "X-Api-Version, X-Request-Id, X-Response-Time",
    +      "server": "Hello API",
    +      "x-request-id": "9496dfdd-4ec7-4b59-aae7-3fed57aed5ba",
    +      "access-control-allow-methods": "GET",
    +      "connection": "close",
    +      "content-length": 16,
    +      "content-md5": "Xmn3QcFXaIaKw9RPUARGBA==",
    +      "content-type": "application/json",
    +      "date": "Wed, 28 Mar 2012 17:39:44 GMT",
    +      "x-response-time": 5
    +    }
    +  },
    +  "msg": "finished",
    +  "time": "2012-03-28T17:39:44.886Z",
    +  "v": 0
    +}
    +
    + +

    Two useful details of note here:

    + +
      +
    1. The last two log messages include a "req_id" field (added to the req.log logger by restify). Note that this is the same UUID as the "X-Request-Id" header in the curl response. This means that if you use req.log for logging in your API handlers you will get an easy way to collate all logging for particular requests.

      + +

      If your's is an SOA system with many services, a best practice is to carry that X-Request-Id/req_id through your system to enable collating handling of a single top-level request.

    2. +
    3. The last two log messages include a "route" field. This tells you to which handler restify routed the request. While possibly useful for debugging, this can be very helpful for log-based monitoring of endpoints on a server.

    4. +
    + +

    Recall that we also setup all logging to go the "hello.log" file. This was set at the TRACE level. Restify will log more detail of its operation at the trace level. See my "hello.log" for an example. The bunyan tool does a decent job of nicely formatting multiline messages and "req"/"res" keys (with color, not shown in the gist).

    + +

    This is logging you can use effectively.

    + +

    Other Tools

    + +

    Bunyan is just one of many options for logging in node.js-land. Others (that I know of) supporting JSON logging are winston and logmagic. Paul Querna has an excellent post on using JSON for logging, which shows logmagic usage and also touches on topics like the GELF logging format, log transporting, indexing and searching.

    + +

    Final Thoughts

    + +

    Parsing challenges won't ever completely go away, but it can for your logs if you use JSON. Collating log records across logs from multiple nodes is facilitated by a common "time" field. Correlating logging across multiple services is enabled by carrying a common "req_id" (or equivalent) through all such logs.

    + +

    Separate log files for a single service is an anti-pattern. The typical Apache example of separate access and error logs is legacy, not an example to follow. A JSON log provides the structure necessary for tooling to easily filter for log records of a particular type.

    + +

    JSON logs bring possibilities. Feeding to tools like Splunk becomes easy. Ad hoc fields allow for a lightly spec'd comm channel from apps to other services: records with a "metric" could feed to statsd, records with a "loggly: true" could feed to loggly.com.

    + +

    Here I've described a very simple example of restify and bunyan usage for node.js-based API services with easy JSON logging. Restify provides a powerful framework for robust API services. Bunyan provides a light API for nice JSON logging and the beginnings of tooling to help consume Bunyan JSON logs.

    + +

    Update (29-Mar-2012): Fix styles somewhat for RSS readers.

    diff --git a/doc/blog/npm/managing-node-js-dependencies-with-shrinkwrap.md b/doc/blog/npm/managing-node-js-dependencies-with-shrinkwrap.md new file mode 100644 index 00000000000..26805b7a4c8 --- /dev/null +++ b/doc/blog/npm/managing-node-js-dependencies-with-shrinkwrap.md @@ -0,0 +1,167 @@ +title: Managing Node.js Dependencies with Shrinkwrap +author: Dave Pacheco +date: Mon Feb 27 2012 10:51:59 GMT-0800 (PST) +status: publish +category: npm +slug: managing-node-js-dependencies-with-shrinkwrap + +


    +Photo by Luc Viatour (flickr)

    + +

    Managing dependencies is a fundamental problem in building complex software. The terrific success of github and npm have made code reuse especially easy in the Node world, where packages don't exist in isolation but rather as nodes in a large graph. The software is constantly changing (releasing new versions), and each package has its own constraints about what other packages it requires to run (dependencies). npm keeps track of these constraints, and authors express what kind of changes are compatible using semantic versioning, allowing authors to specify that their package will work with even future versions of its dependencies as long as the semantic versions are assigned properly. + +

    +

    This does mean that when you "npm install" a package with dependencies, there's no guarantee that you'll get the same set of code now that you would have gotten an hour ago, or that you would get if you were to run it again an hour later. You may get a bunch of bug fixes now that weren't available an hour ago. This is great during development, where you want to keep up with changes upstream. It's not necessarily what you want for deployment, though, where you want to validate whatever bits you're actually shipping. + +

    +

    Put differently, it's understood that all software changes incur some risk, and it's critical to be able to manage this risk on your own terms. Taking that risk in development is good because by definition that's when you're incorporating and testing software changes. On the other hand, if you're shipping production software, you probably don't want to take this risk when cutting a release candidate (i.e. build time) or when you actually ship (i.e. deploy time) because you want to validate whatever you ship. + +

    +

    You can address a simple case of this problem by only depending on specific versions of packages, allowing no semver flexibility at all, but this falls apart when you depend on packages that don't also adopt the same principle. Many of us at Joyent started wondering: can we generalize this approach? + +

    +

    Shrinkwrapping packages

    +

    That brings us to npm shrinkwrap[1]: + +

    +
    NAME
    +       npm-shrinkwrap -- Lock down dependency versions
    +
    +SYNOPSIS
    +       npm shrinkwrap
    +
    +DESCRIPTION
    +       This  command  locks down the versions of a package's dependencies so
    +       that you can control exactly which versions of each  dependency  will
    +       be used when your package is installed.
    +

    Let's consider package A: + +

    +
    {
    +    "name": "A",
    +    "version": "0.1.0",
    +    "dependencies": {
    +        "B": "<0.1.0"
    +    }
    +}
    +

    package B: + +

    +
    {
    +    "name": "B",
    +    "version": "0.0.1",
    +    "dependencies": {
    +        "C": "<0.1.0"
    +    }
    +}
    +

    and package C: + +

    +
    {
    +    "name": "C,
    +    "version": "0.0.1"
    +}
    +

    If these are the only versions of A, B, and C available in the registry, then a normal "npm install A" will install: + +

    +
    A@0.1.0
    +└─┬ B@0.0.1
    +  └── C@0.0.1
    +

    Then if B@0.0.2 is published, then a fresh "npm install A" will install: + +

    +
    A@0.1.0
    +└─┬ B@0.0.2
    +  └── C@0.0.1
    +

    assuming the new version did not modify B's dependencies. Of course, the new version of B could include a new version of C and any number of new dependencies. As we said before, if A's author doesn't want that, she could specify a dependency on B@0.0.1. But if A's author and B's author are not the same person, there's no way for A's author to say that she does not want to pull in newly published versions of C when B hasn't changed at all. + +

    +

    In this case, A's author can use + +

    +
    # npm shrinkwrap
    +

    This generates npm-shrinkwrap.json, which will look something like this: + +

    +
    {
    +    "name": "A",
    +    "dependencies": {
    +        "B": {
    +            "version": "0.0.1",
    +            "dependencies": {
    +                "C": {  "version": "0.1.0" }
    +            }
    +        }
    +    }
    +}
    +

    The shrinkwrap command has locked down the dependencies based on what's currently installed in node_modules. When "npm install" installs a package with a npm-shrinkwrap.json file in the package root, the shrinkwrap file (rather than package.json files) completely drives the installation of that package and all of its dependencies (recursively). So now the author publishes A@0.1.0, and subsequent installs of this package will use B@0.0.1 and C@0.1.0, regardless the dependencies and versions listed in A's, B's, and C's package.json files. If the authors of B and C publish new versions, they won't be used to install A because the shrinkwrap refers to older versions. Even if you generate a new shrinkwrap, it will still reference the older versions, since "npm shrinkwrap" uses what's installed locally rather than what's available in the registry. + +

    +

    Using shrinkwrapped packages

    +

    Using a shrinkwrapped package is no different than using any other package: you can "npm install" it by hand, or add a dependency to your package.json file and "npm install" it. + +

    +

    Building shrinkwrapped packages

    +

    To shrinkwrap an existing package: + +

    +
      +
    1. Run "npm install" in the package root to install the current versions of all dependencies.
    2. +
    3. Validate that the package works as expected with these versions.
    4. +
    5. Run "npm shrinkwrap", add npm-shrinkwrap.json to git, and publish your package.
    6. +
    +

    To add or update a dependency in a shrinkwrapped package: + +

    +
      +
    1. Run "npm install" in the package root to install the current versions of all dependencies.
    2. +
    3. Add or update dependencies. "npm install" each new or updated package individually and then update package.json.
    4. +
    5. Validate that the package works as expected with the new dependencies.
    6. +
    7. Run "npm shrinkwrap", commit the new npm-shrinkwrap.json, and publish your package.
    8. +
    +

    You can still use npm outdated(1) to view which dependencies have newer versions available. + +

    +

    For more details, check out the full docs on npm shrinkwrap, from which much of the above is taken. + +

    +

    Why not just check node_modules into git?

    +

    One previously proposed solution is to "npm install" your dependencies during development and commit the results into source control. Then you deploy your app from a specific git SHA knowing you've got exactly the same bits that you tested in development. This does address the problem, but it has its own issues: for one, binaries are tricky because you need to "npm install" them to get their sources, but this builds the [system-dependent] binary too. You can avoid checking in the binaries and use "npm rebuild" at build time, but we've had a lot of difficulty trying to do this.[2] At best, this is second-class treatment for binary modules, which are critical for many important types of Node applications.[3] + +

    +

    Besides the issues with binary modules, this approach just felt wrong to many of us. There's a reason we don't check binaries into source control, and it's not just because they're platform-dependent. (After all, we could build and check in binaries for all supported platforms and operating systems.) It's because that approach is error-prone and redundant: error-prone because it introduces a new human failure mode where someone checks in a source change but doesn't regenerate all the binaries, and redundant because the binaries can always be built from the sources alone. An important principle of software version control is that you don't check in files derived directly from other files by a simple transformation.[4] Instead, you check in the original sources and automate the transformations via the build process. + +

    +

    Dependencies are just like binaries in this regard: they're files derived from a simple transformation of something else that is (or could easily be) already available: the name and version of the dependency. Checking them in has all the same problems as checking in binaries: people could update package.json without updating the checked-in module (or vice versa). Besides that, adding new dependencies has to be done by hand, introducing more opportunities for error (checking in the wrong files, not checking in certain files, inadvertently changing files, and so on). Our feeling was: why check in this whole dependency tree (and create a mess for binary add-ons) when we could just check in the package name and version and have the build process do the rest? + +

    +

    Finally, the approach of checking in node_modules doesn't really scale for us. We've got at least a dozen repos that will use restify, and it doesn't make sense to check that in everywhere when we could instead just specify which version each one is using. There's another principle at work here, which is separation of concerns: each repo specifies what it needs, while the build process figures out where to get it. + +

    +

    What if an author republishes an existing version of a package?

    +

    We're not suggesting deploying a shrinkwrapped package directly and running "npm install" to install from shrinkwrap in production. We already have a build process to deal with binary modules and other automateable tasks. That's where we do the "npm install". We tar up the result and distribute the tarball. Since we test each build before shipping, we won't deploy something we didn't test. + +

    +

    It's still possible to pick up newly published versions of existing packages at build time. We assume force publish is not that common in the first place, let alone force publish that breaks compatibility. If you're worried about this, you can use git SHAs in the shrinkwrap or even consider maintaining a mirror of the part of the npm registry that you use and require human confirmation before mirroring unpublishes. + +

    +

    Final thoughts

    +

    Of course, the details of each use case matter a lot, and the world doesn't have to pick just one solution. If you like checking in node_modules, you should keep doing that. We've chosen the shrinkwrap route because that works better for us. + +

    +

    It's not exactly news that Joyent is heavy on Node. Node is the heart of our SmartDataCenter (SDC) product, whose public-facing web portal, public API, Cloud Analytics, provisioning, billing, heartbeating, and other services are all implemented in Node. That's why it's so important to us to have robust components (like logging and REST) and tools for understanding production failures post mortem, profile Node apps in production, and now managing Node dependencies. Again, we're interested to hear feedback from others using these tools. + +

    +
    +Dave Pacheco blogs at dtrace.org. + +

    [1] Much of this section is taken directly from the "npm shrinkwrap" documentation. + +

    +

    [2] We've had a lot of trouble with checking in node_modules with binary dependencies. The first problem is figuring out exactly which files not to check in (.o, .node, .dynlib, .so, *.a, ...). When Mark went to apply this to one of our internal services, the "npm rebuild" step blew away half of the dependency tree because it ran "make clean", which in dependency ldapjs brings the repo to a clean slate by blowing away its dependencies. Later, a new (but highly experienced) engineer on our team was tasked with fixing a bug in our Node-based DHCP server. To fix the bug, we went with a new dependency. He tried checking in node_modules, which added 190,000 lines of code (to this repo that was previously a few hundred LOC). And despite doing everything he could think of to do this correctly and test it properly, the change broke the build because of the binary modules. So having tried this approach a few times now, it appears quite difficult to get right, and as I pointed out above, the lack of actual documentation and real world examples suggests others either aren't using binary modules (which we know isn't true) or haven't had much better luck with this approach. + +

    +

    [3] Like a good Node-based distributed system, our architecture uses lots of small HTTP servers. Each of these serves a REST API using restify. restify uses the binary module node-dtrace-provider, which gives each of our services deep DTrace-based observability for free. So literally almost all of our components are or will soon be depending on a binary add-on. Additionally, the foundation of Cloud Analytics are a pair of binary modules that extract data from DTrace and kstat. So this isn't a corner case for us, and we don't believe we're exceptional in this regard. The popular hiredis package for interfacing with redis from Node is also a binary module. + +

    +

    [4] Note that I said this is an important principle for software version control, not using git in general. People use git for lots of things where checking in binaries and other derived files is probably fine. Also, I'm not interested in proselytizing; if you want to do this for software version control too, go ahead. But don't do it out of ignorance of existing successful software engineering practices.

    diff --git a/doc/blog/npm/npm-1-0-global-vs-local-installation.md b/doc/blog/npm/npm-1-0-global-vs-local-installation.md new file mode 100644 index 00000000000..7c16003d6fa --- /dev/null +++ b/doc/blog/npm/npm-1-0-global-vs-local-installation.md @@ -0,0 +1,64 @@ +title: npm 1.0: Global vs Local installation +author: Isaac Schlueter +date: Wed Mar 23 2011 23:07:13 GMT-0700 (PDT) +status: publish +category: npm +slug: npm-1-0-global-vs-local-installation + +

    npm 1.0 is in release candidate mode. Go get it!

    + +

    More than anything else, the driving force behind the npm 1.0 rearchitecture was the desire to simplify what a package installation directory structure looks like.

    + +

    In npm 0.x, there was a command called bundle that a lot of people liked. bundle let you install your dependencies locally in your project, but even still, it was basically a hack that never really worked very reliably.

    + +

    Also, there was that activation/deactivation thing. That’s confusing.

    + +

    Two paths

    + +

    In npm 1.0, there are two ways to install things:

    + +
    1. globally —- This drops modules in {prefix}/lib/node_modules, and puts executable files in {prefix}/bin, where {prefix} is usually something like /usr/local. It also installs man pages in {prefix}/share/man, if they’re supplied.
    2. locally —- This installs your package in the current working directory. Node modules go in ./node_modules, executables go in ./node_modules/.bin/, and man pages aren’t installed at all.
    + +

    Which to choose

    + +

    Whether to install a package globally or locally depends on the global config, which is aliased to the -g command line switch.

    + +

    Just like how global variables are kind of gross, but also necessary in some cases, global packages are important, but best avoided if not needed.

    + +

    In general, the rule of thumb is:

    + +
    1. If you’re installing something that you want to use in your program, using require('whatever'), then install it locally, at the root of your project.
    2. If you’re installing something that you want to use in your shell, on the command line or something, install it globally, so that its binaries end up in your PATH environment variable.
    + +

    When you can't choose

    + +

    Of course, there are some cases where you want to do both. Coffee-script and Express both are good examples of apps that have a command line interface, as well as a library. In those cases, you can do one of the following:

    + +
    1. Install it in both places. Seriously, are you that short on disk space? It’s fine, really. They’re tiny JavaScript programs.
    2. Install it globally, and then npm link coffee-script or npm link express (if you’re on a platform that supports symbolic links.) Then you only need to update the global copy to update all the symlinks as well.
    + +

    The first option is the best in my opinion. Simple, clear, explicit. The second is really handy if you are going to re-use the same library in a bunch of different projects. (More on npm link in a future installment.)

    + +

    You can probably think of other ways to do it by messing with environment variables. But I don’t recommend those ways. Go with the grain.

    + +

    Slight exception: It’s not always the cwd.

    + +

    Let’s say you do something like this:

    + +
    cd ~/projects/foo     # go into my project
    +npm install express   # ./node_modules/express
    +cd lib/utils          # move around in there
    +vim some-thing.js     # edit some stuff, work work work
    +npm install redis     # ./lib/utils/node_modules/redis!? ew.
    + +

    In this case, npm will install redis into ~/projects/foo/node_modules/redis. Sort of like how git will work anywhere within a git repository, npm will work anywhere within a package, defined by having a node_modules folder.

    + +

    Test runners and stuff

    + +

    If your package's scripts.test command uses a command-line program installed by one of your dependencies, not to worry. npm makes ./node_modules/.bin the first entry in the PATH environment variable when running any lifecycle scripts, so this will work fine, even if your program is not globally installed: + +

    { "name" : "my-program"
    +, "version" : "1.2.3"
    +, "dependencies": { "express": "*", "coffee-script": "*" }
    +, "devDependencies": { "vows": "*" }
    +, "scripts":
    +  { "test": "vows test/*.js"
    +  , "preinstall": "cake build" } }
    diff --git a/doc/blog/npm/npm-1-0-link.md b/doc/blog/npm/npm-1-0-link.md new file mode 100644 index 00000000000..bb0d2f808c6 --- /dev/null +++ b/doc/blog/npm/npm-1-0-link.md @@ -0,0 +1,114 @@ +title: npm 1.0: link +author: Isaac Schlueter +date: Wed Apr 06 2011 17:40:33 GMT-0700 (PDT) +status: publish +category: npm +slug: npm-1-0-link + +

    npm 1.0 is in release candidate mode. Go get it!

    + +

    In npm 0.x, there was a command called link. With it, you could “link-install” a package so that changes would be reflected in real-time. This is especially handy when you’re actually building something. You could make a few changes, run the command again, and voila, your new code would be run without having to re-install every time.

    + +

    Of course, compiled modules still have to be rebuilt. That’s not ideal, but it’s a problem that will take more powerful magic to solve.

    + +

    In npm 0.x, this was a pretty awful kludge. Back then, every package existed in some folder like:

    + +
    prefix/lib/node/.npm/my-package/1.3.6/package
    +
    + +

    and the package’s version and name could be inferred from the path. Then, symbolic links were set up that looked like:

    + +
    prefix/lib/node/my-package@1.3.6 -> ./.npm/my-package/1.3.6/package
    +
    + +

    It was easy enough to point that symlink to a different location. However, since the package.json file could change, that meant that the connection between the version and the folder was not reliable.

    + +

    At first, this was just sort of something that we dealt with by saying, “Relink if you change the version.” However, as more and more edge cases arose, eventually the solution was to give link packages this fakey version of “9999.0.0-LINK-hash” so that npm knew it was an imposter. Sometimes the package was treated as if it had the 9999.0.0 version, and other times it was treated as if it had the version specified in the package.json.

    + +

    A better way

    + +

    For npm 1.0, we backed up and looked at what the actual use cases were. Most of the time when you link something you want one of the following:

    + +
      +
    1. globally install this package I’m working on so that I can run the command it creates and test its stuff as I work on it.
    2. +
    3. locally install my thing into some other thing that depends on it, so that the other thing can require() it.
    4. +
    + +

    And, in both cases, changes should be immediately apparent and not require any re-linking.

    + +

    Also, there’s a third use case that I didn’t really appreciate until I started writing more programs that had more dependencies:

    + +
    1. Globally install something, and use it in development in a bunch of projects, and then update them all at once so that they all use the latest version.

    + +

    Really, the second case above is a special-case of this third case.

    + + + +

    The first step is to link your local project into the global install space. (See global vs local installation for more on this global/local business.)

    + +

    I do this as I’m developing node projects (including npm itself).

    + +
    cd ~/dev/js/node-tap  # go into the project dir
    +npm link              # create symlinks into {prefix}
    +
    + +

    Because of how I have my computer set up, with /usr/local as my install prefix, I end up with a symlink from /usr/local/lib/node_modules/tap pointing to ~/dev/js/node-tap, and the executable linked to /usr/local/bin/tap.

    + +

    Of course, if you set your paths differently, then you’ll have different results. (That’s why I tend to talk in terms of prefix rather than /usr/local.)

    + + + +

    When you want to link the globally-installed package into your local development folder, you run npm link pkg where pkg is the name of the package that you want to install.

    + +

    For example, let’s say that I wanted to write some tap tests for my node-glob package. I’d first do the steps above to link tap into the global install space, and then I’d do this:

    + +
    cd ~/dev/js/node-glob  # go to the project that uses the thing.
    +npm link tap           # link the global thing into my project.
    +
    + +

    Now when I make changes in ~/dev/js/node-tap, they’ll be immediately reflected in ~/dev/js/node-glob/node_modules/tap.

    + + + +

    Let’s say I have 15 sites that all use express. I want the benefits of local development, but I also want to be able to update all my dev folders at once. You can globally install express, and then link it into your local development folder.

    + +
    npm install express -g  # install express globally
    +cd ~/dev/js/my-blog     # development folder one
    +npm link express        # link the global express into ./node_modules
    +cd ~/dev/js/photo-site  # other project folder
    +npm link express        # link express into here, as well
    +
    +                        # time passes
    +                        # TJ releases some new stuff.
    +                        # you want this new stuff.
    +
    +npm update express -g   # update the global install.
    +                        # this also updates my project folders.
    +
    + +

    Caveat: Not For Real Servers

    + +

    npm link is a development tool. It’s awesome for managing packages on your local development box. But deploying with npm link is basically asking for problems, since it makes it super easy to update things without realizing it.

    + +

    Caveat 2: Sorry, Windows!

    + +

    I highly doubt that a native Windows node will ever have comparable symbolic link support to what Unix systems provide. I know that there are junctions and such, and I've heard legends about symbolic links on Windows 7.

    + +

    When there is a native windows port of Node, if that native windows port has `fs.symlink` and `fs.readlink` support that is exactly identical to the way that they work on Unix, then this should work fine.

    + +

    But I wouldn't hold my breath. Any bugs about this not working on a native Windows system (ie, not Cygwin) will most likely be closed with wontfix.

    + + +

    Aside: Credit where Credit’s Due

    + +

    Back before the Great Package Management Wars of Node 0.1, before npm or kiwi or mode or seed.js could do much of anything, and certainly before any of them had more than 2 users, Mikeal Rogers invited me to the Couch.io offices for lunch to talk about this npm registry thingie I’d mentioned wanting to build. (That is, to convince me to use CouchDB for it.)

    + +

    Since he was volunteering to build the first version of it, and since couch is pretty much the ideal candidate for this use-case, it was an easy sell.

    + +

    While I was there, he said, “Look. You need to be able to link a project directory as if it was installed as a package, and then have it all Just Work. Can you do that?”

    + +

    I was like, “Well, I don’t know… I mean, there’s these edge cases, and it doesn’t really fit with the existing folder structure very well…”

    + +

    “Dude. Either you do it, or I’m going to have to do it, and then there’ll be another package manager in node, instead of writing a registry for npm, and it won’t be as good anyway. Don’t be python.”

    + +

    The rest is history.

    diff --git a/doc/blog/npm/npm-1-0-released.md b/doc/blog/npm/npm-1-0-released.md new file mode 100644 index 00000000000..ea26989c670 --- /dev/null +++ b/doc/blog/npm/npm-1-0-released.md @@ -0,0 +1,36 @@ +title: npm 1.0: Released +author: Isaac Schlueter +date: Sun May 01 2011 08:09:45 GMT-0700 (PDT) +status: publish +category: npm +slug: npm-1-0-released + +

    npm 1.0 has been released. Here are the highlights:

    + +
    • Global vs local installation
    • ls displays a tree, instead of being a remote search
    • No more “activation” concept - dependencies are nested
    • Updates to link command
    • Install script cleans up any 0.x cruft it finds. (That is, it removes old packages, so that they can be installed properly.)
    • Simplified “search” command. One line per package, rather than one line per version.
    • Renovated “completion” approach
    • More help topics
    • Simplified folder structure
    + +

    The focus is on npm being a development tool, rather than an apt-wannabe.

    + +

    Installing it

    + +

    To get the new version, run this command:

    + +
    curl http://npmjs.org/install.sh | sh 
    + +

    This will prompt to ask you if it’s ok to remove all the old 0.x cruft. If you want to not be asked, then do this:

    + +
    curl http://npmjs.org/install.sh | clean=yes sh 
    + +

    Or, if you want to not do the cleanup, and leave the old stuff behind, then do this:

    + +
    curl http://npmjs.org/install.sh | clean=no sh 
    + +

    A lot of people in the node community were brave testers and helped make this release a lot better (and swifter) than it would have otherwise been. Thanks :)

    + +

    Code Freeze

    + +

    npm will not have any major feature enhancements or architectural changes for at least 6 months. There are interesting developments planned that leverage npm in some ways, but it’s time to let the client itself settle. Also, I want to focus attention on some other problems for a little while.

    + +

    Of course, bug reports are always welcome.

    + +

    See you at NodeConf!

    diff --git a/doc/blog/npm/npm-1-0-the-new-ls.md b/doc/blog/npm/npm-1-0-the-new-ls.md new file mode 100644 index 00000000000..da820a0d8b1 --- /dev/null +++ b/doc/blog/npm/npm-1-0-the-new-ls.md @@ -0,0 +1,144 @@ +title: npm 1.0: The New "ls" +author: Isaac Schlueter +date: Thu Mar 17 2011 23:22:17 GMT-0700 (PDT) +status: publish +category: npm +slug: npm-1-0-the-new-ls + +

    This is the first in a series of hopefully more than 1 posts, each detailing some aspect of npm 1.0.

    + +

    In npm 0.x, the ls command was a combination of both searching the registry as well as reporting on what you have installed.

    + +

    As the registry has grown in size, this has gotten unwieldy. Also, since npm 1.0 manages dependencies differently, nesting them in node_modules folder and installing locally by default, there are different things that you want to view.

    + +

    The functionality of the ls command was split into two different parts. search is now the way to find things on the registry (and it only reports one line per package, instead of one line per version), and ls shows a tree view of the packages that are installed locally.

    + +

    Here’s an example of the output:

    + +
    $ npm ls
    +npm@1.0.0 /Users/isaacs/dev-src/js/npm
    +├── semver@1.0.1 
    +├─┬ ronn@0.3.5 
    +│ └── opts@1.2.1 
    +└─┬ express@2.0.0rc3 extraneous 
    +  ├─┬ connect@1.1.0 
    +  │ ├── qs@0.0.7 
    +  │ └── mime@1.2.1 
    +  ├── mime@1.2.1 
    +  └── qs@0.0.7
    +
    + +

    This is after I’ve done npm install semver ronn express in the npm source directory. Since express isn’t actually a dependency of npm, it shows up with that “extraneous” marker.

    + +

    Let’s see what happens when we create a broken situation:

    + +
    $ rm -rf ./node_modules/express/node_modules/connect
    +$ npm ls
    +npm@1.0.0 /Users/isaacs/dev-src/js/npm
    +├── semver@1.0.1 
    +├─┬ ronn@0.3.5 
    +│ └── opts@1.2.1 
    +└─┬ express@2.0.0rc3 extraneous 
    +  ├── UNMET DEPENDENCY connect >= 1.1.0 < 2.0.0
    +  ├── mime@1.2.1 
    +  └── qs@0.0.7
    +
    + +

    Tree views are great for human readability, but some times you want to pipe that stuff to another program. For that output, I took the same datastructure, but instead of building up a treeview string for each line, it spits out just the folders like this:

    + +
    $ npm ls -p
    +/Users/isaacs/dev-src/js/npm
    +/Users/isaacs/dev-src/js/npm/node_modules/semver
    +/Users/isaacs/dev-src/js/npm/node_modules/ronn
    +/Users/isaacs/dev-src/js/npm/node_modules/ronn/node_modules/opts
    +/Users/isaacs/dev-src/js/npm/node_modules/express
    +/Users/isaacs/dev-src/js/npm/node_modules/express/node_modules/connect
    +/Users/isaacs/dev-src/js/npm/node_modules/express/node_modules/connect/node_modules/qs
    +/Users/isaacs/dev-src/js/npm/node_modules/express/node_modules/connect/node_modules/mime
    +/Users/isaacs/dev-src/js/npm/node_modules/express/node_modules/mime
    +/Users/isaacs/dev-src/js/npm/node_modules/express/node_modules/qs
    +
    + +

    Since you sometimes want a bigger view, I added the --long option to (shorthand: -l) to spit out more info:

    + +
    $ npm ls -l
    +npm@1.0.0 
    +│ /Users/isaacs/dev-src/js/npm
    +│ A package manager for node
    +│ git://github.com/isaacs/npm.git
    +│ http://npmjs.org/
    +├── semver@1.0.1 
    +│   ./node_modules/semver
    +│   The semantic version parser used by npm.
    +│   git://github.com/isaacs/node-semver.git
    +├─┬ ronn@0.3.5 
    +│ │ ./node_modules/ronn
    +│ │ markdown to roff and html converter
    +│ └── opts@1.2.1 
    +│     ./node_modules/ronn/node_modules/opts
    +│     Command line argument parser written in the style of commonjs. To be used with node.js
    +└─┬ express@2.0.0rc3 extraneous 
    +  │ ./node_modules/express
    +  │ Sinatra inspired web development framework
    +  ├─┬ connect@1.1.0 
    +  │ │ ./node_modules/express/node_modules/connect
    +  │ │ High performance middleware framework
    +  │ │ git://github.com/senchalabs/connect.git
    +  │ ├── qs@0.0.7 
    +  │ │   ./node_modules/express/node_modules/connect/node_modules/qs
    +  │ │   querystring parser
    +  │ └── mime@1.2.1 
    +  │     ./node_modules/express/node_modules/connect/node_modules/mime
    +  │     A comprehensive library for mime-type mapping
    +  ├── mime@1.2.1 
    +  │   ./node_modules/express/node_modules/mime
    +  │   A comprehensive library for mime-type mapping
    +  └── qs@0.0.7 
    +      ./node_modules/express/node_modules/qs
    +      querystring parser
    +
    +$ npm ls -lp
    +/Users/isaacs/dev-src/js/npm:npm@1.0.0::::
    +/Users/isaacs/dev-src/js/npm/node_modules/semver:semver@1.0.1::::
    +/Users/isaacs/dev-src/js/npm/node_modules/ronn:ronn@0.3.5::::
    +/Users/isaacs/dev-src/js/npm/node_modules/ronn/node_modules/opts:opts@1.2.1::::
    +/Users/isaacs/dev-src/js/npm/node_modules/express:express@2.0.0rc3:EXTRANEOUS:::
    +/Users/isaacs/dev-src/js/npm/node_modules/express/node_modules/connect:connect@1.1.0::::
    +/Users/isaacs/dev-src/js/npm/node_modules/express/node_modules/connect/node_modules/qs:qs@0.0.7::::
    +/Users/isaacs/dev-src/js/npm/node_modules/express/node_modules/connect/node_modules/mime:mime@1.2.1::::
    +/Users/isaacs/dev-src/js/npm/node_modules/express/node_modules/mime:mime@1.2.1::::
    +/Users/isaacs/dev-src/js/npm/node_modules/express/node_modules/qs:qs@0.0.7::::
    +
    + +

    And, if you want to get at the globally-installed modules, you can use ls with the global flag:

    + +
    $ npm ls -g
    +/usr/local
    +├─┬ A@1.2.3 -> /Users/isaacs/dev-src/js/A
    +│ ├── B@1.2.3 -> /Users/isaacs/dev-src/js/B
    +│ └─┬ npm@0.3.15 
    +│   └── semver@1.0.1 
    +├─┬ B@1.2.3 -> /Users/isaacs/dev-src/js/B
    +│ └── A@1.2.3 -> /Users/isaacs/dev-src/js/A
    +├── glob@2.0.5 
    +├─┬ npm@1.0.0 -> /Users/isaacs/dev-src/js/npm
    +│ ├── semver@1.0.1 
    +│ └─┬ ronn@0.3.5 
    +│   └── opts@1.2.1 
    +└── supervisor@0.1.2 -> /Users/isaacs/dev-src/js/node-supervisor
    +
    +$ npm ls -gpl
    +/usr/local:::::
    +/usr/local/lib/node_modules/A:A@1.2.3::::/Users/isaacs/dev-src/js/A
    +/usr/local/lib/node_modules/A/node_modules/npm:npm@0.3.15::::/Users/isaacs/dev-src/js/A/node_modules/npm
    +/usr/local/lib/node_modules/A/node_modules/npm/node_modules/semver:semver@1.0.1::::/Users/isaacs/dev-src/js/A/node_modules/npm/node_modules/semver
    +/usr/local/lib/node_modules/B:B@1.2.3::::/Users/isaacs/dev-src/js/B
    +/usr/local/lib/node_modules/glob:glob@2.0.5::::
    +/usr/local/lib/node_modules/npm:npm@1.0.0::::/Users/isaacs/dev-src/js/npm
    +/usr/local/lib/node_modules/npm/node_modules/semver:semver@1.0.1::::/Users/isaacs/dev-src/js/npm/node_modules/semver
    +/usr/local/lib/node_modules/npm/node_modules/ronn:ronn@0.3.5::::/Users/isaacs/dev-src/js/npm/node_modules/ronn
    +/usr/local/lib/node_modules/npm/node_modules/ronn/node_modules/opts:opts@1.2.1::::/Users/isaacs/dev-src/js/npm/node_modules/ronn/node_modules/opts
    +/usr/local/lib/node_modules/supervisor:supervisor@0.1.2::::/Users/isaacs/dev-src/js/node-supervisor
    +
    + +

    Those -> flags are indications that the package is link-installed, which will be covered in the next installment.

    diff --git a/doc/blog/release/node-v0-4-10.md b/doc/blog/release/node-v0-4-10.md new file mode 100644 index 00000000000..a7a14d60d59 --- /dev/null +++ b/doc/blog/release/node-v0-4-10.md @@ -0,0 +1,25 @@ +version: 0.4.10 +title: Node v0.4.10 +author: ryandahl +date: Wed Jul 20 2011 07:36:38 GMT-0700 (PDT) +status: publish +category: release +slug: node-v0-4-10 + +2011.07.19, Version 0.4.10 (stable) +
    • #394 Fix Buffer drops last null character in UTF-8 +
    • #829 Backport r8577 from V8 (Ben Noordhuis) +
    • #877 Don't wait for HTTP Agent socket pool to establish connections. +
    • #915 Find kqueue on FreeBSD correctly (Brett Kiefer) +
    • #1085 HTTP: Fix race in abort/dispatch code (Stefan Rusu) +
    • #1274 debugger improvement (Yoshihiro Kikuchi) +
    • #1291 Properly respond to HEAD during end(body) hot path (Reid Burke) +
    • #1304 TLS: Fix race in abort/connection code (Stefan Rusu) +
    • #1360 Allow _ in url hostnames. +
    • Revert 37d529f8 - unbreaks debugger command parsing. +
    • Bring back global execScript +
    • Doc improvements
    + +Download: http://nodejs.org/dist/node-v0.4.10.tar.gz +Website: http://nodejs.org/docs/v0.4.10 +Documentation: http://nodejs.org/docs/v0.4.10/api diff --git a/doc/blog/release/node-v0-4-11.md b/doc/blog/release/node-v0-4-11.md new file mode 100644 index 00000000000..eca36d3ac33 --- /dev/null +++ b/doc/blog/release/node-v0-4-11.md @@ -0,0 +1,39 @@ +version: 0.4.11 +title: Node v0.4.11 +author: ryandahl +date: Thu Aug 18 2011 01:44:42 GMT-0700 (PDT) +status: publish +category: release +slug: node-v0-4-11 + +2011.08.17, Version 0.4.11 (stable) +
    • #738 Fix crypto encryption/decryption with Base64. (SAWADA Tadashi) + +
    • #1202 net.createConnection defer DNS lookup error events to next tick (Ben Noordhuis) + +
    • #1374 fix setting ServerResponse.statusCode in writeHead (Trent Mick) + +
    • #1417 Fix http.ClientRequest crashes if end() was called twice + +
    • #1497 querystring: Replace 'in' test with 'hasOwnProperty' (isaacs) + +
    • #1546 http perf improvement + +
    • fix memleak in libeio (Tom Hughes) + +
    • cmake improvements (Tom Hughes) + +
    • node_net.cc: fix incorrect sizeof() (Tom Hughes) + +
    • Windows/cygwin: no more GetConsoleTitleW errors on XP (Bert Belder) + +
    • Doc improvements (koichik, Logan Smyth, Ben Noordhuis, Arnout Kazemier)
    + + + + +Download: http://nodejs.org/dist/node-v0.4.11.tar.gz + +Website: http://nodejs.org/docs/v0.4.11/ + +Documentation: http://nodejs.org/docs/v0.4.11/api/ diff --git a/doc/blog/release/node-v0-4-12.md b/doc/blog/release/node-v0-4-12.md new file mode 100644 index 00000000000..0e9aedd7045 --- /dev/null +++ b/doc/blog/release/node-v0-4-12.md @@ -0,0 +1,29 @@ +version: 0.4.12 +title: Node v0.4.12 +author: ryandahl +date: Thu Sep 15 2011 17:32:07 GMT-0700 (PDT) +status: publish +category: release +slug: node-v0-4-12 + +2011.09.15, Version 0.4.12 (stable) + +
      +
    • Improve docs +
    • #1563 overflow in ChildProcess custom_fd. +
    • #1569, parse error on multi-line HTTP headers. (Ben Noordhuis) +
    • #1586 net: Socket write encoding case sensitivity (koichik) +
    • #1610 Remove DigiNotar CA from trusted list (isaacs) +
    • #1624 buffer: Avoid overrun with 'binary' encoding. (koichik) +
    • #1633 buffer: write() should always set _charsWritten. (koichik) +
    • #1707 hasOwnProperty usage security hole in querystring (isaacs) +
    • #1719 Drain OpenSSL error queue +
    • Fix error reporting in net.Server.listen
    + + + +Download: http://nodejs.org/dist/node-v0.4.12.tar.gz + +Website: http://nodejs.org/docs/v0.4.12/ + +Documentation: http://nodejs.org/docs/v0.4.12/api/ diff --git a/doc/blog/release/node-v0-4-3.md b/doc/blog/release/node-v0-4-3.md new file mode 100644 index 00000000000..e7672f84936 --- /dev/null +++ b/doc/blog/release/node-v0-4-3.md @@ -0,0 +1,33 @@ +version: 0.4.3 +title: Node v0.4.3 +author: ryandahl +date: Fri Mar 18 2011 22:17:59 GMT-0700 (PDT) +status: publish +category: release +slug: node-v0-4-3 + +2011.03.18, Version 0.4.3 (stable) +
      +
    • Don't decrease server connection counter again if destroy() is called more than once GH-431 (Andreas Reich, Anders Conbere) +
    • Documentation improvements (koichik) +
    • Fix bug with setMaxListeners GH-682 +
    • Start up memory footprint improvement. (Tom Hughes) +
    • Solaris improvements. +
    • Buffer::Length(Buffer*) should not invoke itself recursively GH-759 (Ben Noordhuis) +
    • TLS: Advertise support for client certs GH-774 (Theo Schlossnagle) +
    • HTTP Agent bugs: GH-787, GH-784, GH-803. +
    • Don't call GetMemoryUsage every 5 seconds. +
    • Upgrade V8 to 3.1.8.3 +
    + + + +Download: http://nodejs.org/dist/node-v0.4.3.tar.gz + +Website: http://nodejs.org/docs/v0.4.3/ + +Documentation: http://nodejs.org/docs/v0.4.3/api + +Announcement + +commit diff --git a/doc/blog/release/node-v0-4-4.md b/doc/blog/release/node-v0-4-4.md new file mode 100644 index 00000000000..6c911ccebd2 --- /dev/null +++ b/doc/blog/release/node-v0-4-4.md @@ -0,0 +1,27 @@ +version: 0.4.4 +title: Node v0.4.4 +author: ryandahl +date: Sat Mar 26 2011 08:58:45 GMT-0700 (PDT) +status: publish +category: release +slug: node-v0-4-4 + +2011.03.26, Version 0.4.4 (stable) +
      +
    • CryptoStream.end shouldn't throw if not writable GH-820 +
    • Drop out if connection destroyed before connect() GH-819 +
    • expose https.Agent +
    • Correctly setsid in tty.open GH-815 +
    • Bug fix for failed buffer construction +
    • Added support for removing .once listeners (GH-806) +
    • Upgrade V8 to 3.1.8.5
    + + + +Download: http://nodejs.org/dist/node-v0.4.4.tar.gz + +Website: http://nodejs.org/docs/v0.4.4 + +Documentation: http://nodejs.org/docs/v0.4.4/api + +announcement diff --git a/doc/blog/release/node-v0-4-5.md b/doc/blog/release/node-v0-4-5.md new file mode 100644 index 00000000000..a27c56cc771 --- /dev/null +++ b/doc/blog/release/node-v0-4-5.md @@ -0,0 +1,29 @@ +version: 0.4.5 +title: node v0.4.5 +author: ryandahl +date: Sat Apr 02 2011 02:04:58 GMT-0700 (PDT) +status: publish +category: release +slug: node-v0-4-5 + +2011.04.01, Version 0.4.5 (stable) +
      +
    • Fix listener leak in stream.pipe() (Mikeal Rogers) +
    • Retain buffers in fs.read/write() GH-814 (Jorge Chamorro Bieling) +
    • TLS performance improvements +
    • SlowBuffer.prototype.slice bug GH-843 +
    • process.stderr.write should return true +
    • Immediate pause/resume race condition GH-535 (isaacs) +
    • Set default host header properly GH-721 (isaacs) +
    • Upgrade V8 to 3.1.8.8
    + + + +Download: http://nodejs.org/dist/node-v0.4.5.tar.gz + +Website: http://nodejs.org/docs/v0.4.5 + +Documentation: http://nodejs.org/docs/v0.4.5/api + + +announcement diff --git a/doc/blog/release/node-v0-4-6.md b/doc/blog/release/node-v0-4-6.md new file mode 100644 index 00000000000..0e4e8871229 --- /dev/null +++ b/doc/blog/release/node-v0-4-6.md @@ -0,0 +1,27 @@ +version: 0.4.6 +title: Node v0.4.6 +author: ryandahl +date: Thu Apr 14 2011 05:00:30 GMT-0700 (PDT) +status: publish +category: release +slug: node-v0-4-6 + +2011.04.13, Version 0.4.6 (stable) +
    • Don't error on ENOTCONN from shutdown() #670 +
    • Auto completion of built-in debugger suggests prefix match rather than partial match. (koichik) +
    • circular reference in vm modules. #822 (Jakub Lekstan) +
    • http response.readable should be false after 'end' #867 (Abe Fettig) +
    • Implemenet os.cpus() and os.uptime() on Solaris (Scott McWhirter) +
    • fs.ReadStream: Allow omission of end option for range reads #801 (Felix Geisendörfer) +
    • Buffer.write() with UCS-2 should not be write partial char #916 (koichik) +
    • Pass secureProtocol through on tls.Server creation (Theo Schlossnagle) +
    • TLS use RC4-SHA by default +
    • Don't strangely drop out of event loop on HTTPS client uploads #892 +
    • Doc improvements +
    • Upgrade v8 to 3.1.8.10
    + +Download: http://nodejs.org/dist/node-v0.4.6.tar.gz + +Website: http://nodejs.org/docs/v0.4.6/ + +Documentation: http://nodejs.org/docs/v0.4.6/api/ diff --git a/doc/blog/release/node-v0-4-7.md b/doc/blog/release/node-v0-4-7.md new file mode 100644 index 00000000000..38816c8134e --- /dev/null +++ b/doc/blog/release/node-v0-4-7.md @@ -0,0 +1,23 @@ +version: 0.4.7 +title: Node v0.4.7 +author: ryandahl +date: Sat Apr 23 2011 00:47:55 GMT-0700 (PDT) +status: publish +category: release +slug: node-v0-4-7 + +2011.04.22, Version 0.4.7 (stable) +
    • Don't emit error on ECONNRESET from read() #670 +
    • Fix: Multiple pipes to the same stream were broken #929 (Felix Geisendörfer) +
    • URL parsing/formatting corrections #954 (isaacs) +
    • make it possible to do repl.start('', stream) (Wade Simmons) +
    • Add os.loadavg for SunOS (Robert Mustacchi) +
    • Fix timeouts with floating point numbers #897 (Jorge Chamorro Bieling) +
    • Improve docs.
    + + +Download: http://nodejs.org/dist/node-v0.4.7.tar.gz + +Website: http://nodejs.org/docs/v0.4.7/ + +Documentation: http://nodejs.org/docs/v0.4.7/api diff --git a/doc/blog/release/node-v0-4-8.md b/doc/blog/release/node-v0-4-8.md new file mode 100644 index 00000000000..b7859edec0d --- /dev/null +++ b/doc/blog/release/node-v0-4-8.md @@ -0,0 +1,55 @@ +version: 0.4.8 +title: Node v0.4.8 +author: ryandahl +date: Sat May 21 2011 07:06:00 GMT-0700 (PDT) +status: publish +category: release +slug: node-v0-4-8 + +2011.05.20, Version 0.4.8 (stable) + +* #974 Properly report traceless errors (isaacs) + +* #983 Better JSON.parse error detection in REPL (isaacs) + +* #836 Agent socket errors bubble up to req only if req exists + +* #1041 Fix event listener leak check timing (koichik) + +* #1038 Fix dns.resolve() with 'PTR' throws Error: Unknown type "PTR" + (koichik) + +* #1073 Share SSL context between server connections (Fedor Indutny) + +* Disable compression with OpenSSL. Improves memory perf. + +* Implement os.totalmem() and os.freemem() for SunOS (Alexandre Marangone) + +* Fix a special characters in URL regression (isaacs) + +* Fix idle timeouts in HTTPS (Felix Geisendörfer) + +* SlowBuffer.write() with 'ucs2' throws ReferenceError. (koichik) + +* http.ServerRequest 'close' sometimes gets an error argument + (Felix Geisendörfer) + +* Doc improvements + +* cleartextstream.destroy() should close(2) the socket. Previously was being + mapped to a shutdown(2) syscall. + +* No longer compile out asserts and debug statements in normal build. + +* Debugger improvements. + +* Upgrade V8 to 3.1.8.16. + + + + +Website: http://nodejs.org/docs/v0.4.8/ + +Download: http://nodejs.org/dist/node-v0.4.8.tar.gz + +Documentation: http://nodejs.org/docs/v0.4.8/api/ diff --git a/doc/blog/release/node-v0-4-9.md b/doc/blog/release/node-v0-4-9.md new file mode 100644 index 00000000000..e2eccf2e0c9 --- /dev/null +++ b/doc/blog/release/node-v0-4-9.md @@ -0,0 +1,30 @@ +version: 0.4.9 +title: Node v0.4.9 +author: ryandahl +date: Wed Jun 29 2011 11:41:05 GMT-0700 (PDT) +status: publish +category: release +slug: node-v0-4-9 + +2011.06.29, Version 0.4.9 (stable)
      +
    • Improve documentation +
    • #1095 error handling bug in stream.pipe() (Felix Geisendörfer) +
    • #1097 Fix a few leaks in node_crypto.cc (Ben Noordhuis) +
    • #562 #1078 Parse file:// urls properly (Ryan Petrello) +
    • #880 Option to disable SSLv2 (Jérémy Lal) +
    • #1087 Disabling SSL compression disabled with early OpenSSLs. +
    • #1144 debugger: don't allow users to input non-valid commands (Siddharth Mahendraker) +
    • Perf improvement for util.inherits +
    • #1166 Support for signature verification with RSA/DSA public keys (Mark Cavage) +
    • #1177 Remove node_modules lookup optimization to better support nested project structures (Mathias Buus) +
    • #1203 Add missing scope.Close to fs.sendfileSync +
    • #1187 Support multiple 'link' headers +
    • #1196 Fix -e/--eval can't load module from node_modules (Koichi Kobayashi) +
    • Upgrade V8 to 3.1.8.25, upgrade http-parser.
    + + +Download: http://nodejs.org/dist/node-v0.4.9.tar.gz + +Website: http://nodejs.org/docs/v0.4.9 + +Documentation: http://nodejs.org/docs/v0.4.9/api diff --git a/doc/blog/release/node-v0-5-0-unstable.md b/doc/blog/release/node-v0-5-0-unstable.md new file mode 100644 index 00000000000..883b9a7f319 --- /dev/null +++ b/doc/blog/release/node-v0-5-0-unstable.md @@ -0,0 +1,39 @@ +version: 0.5.0 +title: Node v0.5.0 (Unstable) +author: ryandahl +date: Wed Jul 06 2011 02:23:17 GMT-0700 (PDT) +status: publish +category: release +slug: node-v0-5-0-unstable + +2011.07.05, Version 0.5.0 (unstable) + +
  • New non-default libuv backend to support IOCP on Windows. Use --use-uv to enable. +
  • deprecate http.cat +
  • docs improved. +
  • add child_process.fork +
  • add fs.utimes() and fs.futimes() support (Ben Noordhuis) +
  • add process.uptime() (Tom Huges) +
  • add path.relative (Tony Huang) +
  • add os.getNetworkInterfaces() +
  • add remoteAddress and remotePort for client TCP connections (Brian White) +
  • add secureOptions flag, setting ciphers, SSL_OP_CRYPTOPRO_TLSEXT_BUG to TLS (Theo Schlossnagle) +
  • add process.arch (Nathan Rajlich) +
  • add reading/writing of floats and doubles from/to buffers (Brian White) +
  • Allow script to be read from stdin +
  • #477 add Buffer::fill method to do memset (Konstantin Käfer) +
  • #573 Diffie-Hellman support to crypto module (Håvard Stranden) +
  • #695 add 'hex' encoding to buffer (isaacs) +
  • #851 Update how REPLServer uses contexts (Ben Weaver) +
  • #853 add fs.lchow, fs.lchmod, fs.fchmod, fs.fchown (isaacs) +
  • #889 Allow to remove all EventEmitter listeners at once (Felix Geisendörfer) +
  • #926 OpenSSL NPN support (Fedor Indutny) +
  • #955 Change ^C handling in REPL (isaacs) +
  • #979 add support for Unix Domain Sockets to HTTP (Mark Cavage) +
  • #1173 #1170 add AMD, asynchronous module definition (isaacs) +
  • DTrace probes: support X-Forwarded-For (Dave Pacheco)
+Download: http://nodejs.org/dist/node-v0.5.0.tar.gz + +Website: http://nodejs.org/docs/v0.5.0/ + +Documentation: http://nodejs.org/docs/v0.5.0/api/ diff --git a/doc/blog/release/node-v0-5-1.md b/doc/blog/release/node-v0-5-1.md new file mode 100644 index 00000000000..f9799d40bc1 --- /dev/null +++ b/doc/blog/release/node-v0-5-1.md @@ -0,0 +1,30 @@ +version: 0.5.1 +title: Node v0.5.1 +author: ryandahl +date: Thu Jul 14 2011 23:48:08 GMT-0700 (PDT) +status: publish +category: release +slug: node-v0-5-1 + +2011.07.14, Version 0.5.1 (unstable) +
  • #1233 Fix os.totalmem on FreeBSD amd64 (Artem Zaytsev) +
  • #1149 IDNA and Punycode support in url.parse (Jeremy Selier, Ben Noordhuis, isaacs) +
  • Export $CC and $CXX to uv and V8's build systems +
  • Include pthread-win32 static libraries in build (Igor Zinkovsky) +
  • #1199, #1094 Fix fs can't handle large file on 64bit platform (koichik) +
  • #1281 Make require a public member of module (isaacs) +
  • #1303 Stream.pipe returns the destination (Elijah Insua) +
  • #1229 Addons should not -DEV_MULTIPLICITY=0 (Brian White) +
  • libuv backend improvements +
  • Upgrade V8 to 3.4.10
+ + + + +Download: http://nodejs.org/dist/v0.5.1/node-v0.5.1.tar.gz + +Windows Build: http://nodejs.org/dist/v0.5.1/node.exe + +Documentation: http://nodejs.org/dist/v0.5.1/docs/api/ + +Website: http://nodejs.org/dist/v0.5.1/docs diff --git a/doc/blog/release/node-v0-5-10.md b/doc/blog/release/node-v0-5-10.md new file mode 100644 index 00000000000..47fb9264273 --- /dev/null +++ b/doc/blog/release/node-v0-5-10.md @@ -0,0 +1,41 @@ +version: 0.5.10 +title: Node v0.5.10 +author: ryandahl +date: Fri Oct 21 2011 19:12:31 GMT-0700 (PDT) +status: publish +category: release +slug: node-v0-5-10 + +2011.10.21, Version 0.5.10 (unstable) +
  • Remove cmake build system, support for Cygwin, legacy code base, process.ENV, process.ARGV, process.memoryUsage().vsize, os.openOSHandle
  • +
  • Documentation improvments (Igor Zinkovsky, Bert Belder, Ilya Dmitrichenko, koichik, Maciej Małecki, Guglielmo Ferri, isaacs)
  • +
  • Performance improvements (Daniel Ennis, Bert Belder, Ben Noordhuis)
  • +
  • Long process.title support (Ben Noordhuis)
  • +
  • net: register net.Server callback only once (Simen Brekken)
  • +
  • net: fix connect queue bugs (Ben Noordhuis)
  • +
  • debugger: fix backtrace err handling (Fedor Indutny)
  • +
  • Use getaddrinfo instead of c-ares for dns.lookup
  • +
  • Emit 'end' from crypto streams on close
  • +
  • repl: print out `undefined` (Nathan Rajlich)
  • +
  • #1902 buffer: use NO_NULL_TERMINATION flag (koichik)
  • +
  • #1907 http: Added support for HTTP PATCH verb (Thomas Parslow)
  • +
  • #1644 add GetCPUInfo on windows (Karl Skomski)
  • +
  • #1484, #1834, #1482, #771 Don't use a separate context for the repl. (isaacs)
  • +
  • #1882 zlib Update 'availOutBefore' value, and test (isaacs)
  • +
  • #1888 child_process.fork: don't modify args (koichik)
  • +
  • #1516 tls: requestCert unusable with Firefox and Chrome (koichik)
  • +
  • #1467 tls: The TLS API is inconsistent with the TCP API (koichik)
  • +
  • #1894 net: fix error handling in listen() (koichik)
  • +
  • #1860 console.error now goes through uv_tty_t
  • +
  • Upgrade V8 to 3.7.0
  • +
  • Upgrade GYP to r1081
+ + + +Download: http://nodejs.org/dist/v0.5.10/node-v0.5.10.tar.gz + +Windows Executable: http://nodejs.org/dist/v0.5.10/node.exe + +Website: http://nodejs.org/docs/v0.5.10/ + +Documentation: http://nodejs.org/docs/v0.5.10/api/ diff --git a/doc/blog/release/node-v0-5-2.md b/doc/blog/release/node-v0-5-2.md new file mode 100644 index 00000000000..c44690f346b --- /dev/null +++ b/doc/blog/release/node-v0-5-2.md @@ -0,0 +1,27 @@ +version: 0.5.2 +title: Node v0.5.2 +author: ryandahl +date: Fri Jul 22 2011 11:40:22 GMT-0700 (PDT) +status: publish +category: release +slug: node-v0-5-2 + +2011.07.22, Version 0.5.2 (unstable) +
  • libuv improvements; named pipe support +
  • #1242 check for SSL_COMP_get_compression_methods() (Ben Noordhuis) +
  • #1348 remove require.paths (isaacs) +
  • #1349 Delimit NODE_PATH with ; on Windows (isaacs) +
  • #1335 Remove EventEmitter from C++ +
  • #1357 Load json files with require() (isaacs) +
  • #1374 fix setting ServerResponse.statusCode in writeHead (Trent Mick) +
  • Fixed: GC was being run too often. +
  • Upgrade V8 to 3.4.14 +
  • doc improvements
+ +Download: http://nodejs.org/dist/v0.5.2/node-v0.5.2.tar.gz + +Windows Executable: http://nodejs.org/dist/v0.5.2/node.exe + +Website: http://nodejs.org/dist/v0.5.2/docs/ + +Documentation: http://nodejs.org/dist/v0.5.2/docs/api diff --git a/doc/blog/release/node-v0-5-3.md b/doc/blog/release/node-v0-5-3.md new file mode 100644 index 00000000000..f84a955f554 --- /dev/null +++ b/doc/blog/release/node-v0-5-3.md @@ -0,0 +1,53 @@ +version: 0.5.3 +title: Node v0.5.3 +author: ryandahl +date: Tue Aug 02 2011 08:03:06 GMT-0700 (PDT) +status: publish +category: release +slug: node-v0-5-3 + +2011.08.01, Version 0.5.3 (unstable) + +
  • Fix crypto encryption/decryption with Base64. (SAWADA Tadashi) + +
  • #243 Add an optional length argument to Buffer.write() (koichik) + +
  • #657 convert nonbuffer data to string in fs.writeFile/Sync (Daniel Pihlström) + +
  • Add process.features, remove process.useUV (Ben Noordhuis) + +
  • #324 Fix crypto hmac to accept binary keys + add test cases from rfc 2202 and 4231 (Stefan Bühler) + +
  • Add Socket::bytesRead, Socket::bytesWritten (Alexander Uvarov) + +
  • #572 Don't print result of --eval in CLI (Ben Noordhuis) + +
  • #1223 Fix http.ClientRequest crashes if end() was called twice (koichik) + +
  • #1383 Emit 'close' after all connections have closed (Felix Geisendörfer) + +
  • Add sprintf-like util.format() function (Ben Noordhuis) + +
  • Add support for TLS SNI (Fedor Indutny) + +
  • New http agent implementation. Off by default the command line flag --use-http2 will enable it. make test-http2 will run the tests for the new implementation. (Mikeal Rogers) + +
  • Revert AMD compatibility. (isaacs) + +
  • Windows: improvements, child_process support. + +
  • Remove pkg-config file. + +
  • Fix startup time regressions. + +
  • doc improvements
+ + + +Download: http://nodejs.org/dist/v0.5.3/node-v0.5.3.tar.gz + +Windows Executable: http://nodejs.org/dist/v0.5.3/node.exe + +Website: http://nodejs.org/dist/v0.5.3/docs + +Documentation: http://nodejs.org/dist/v0.5.3/docs/api diff --git a/doc/blog/release/node-v0-5-4.md b/doc/blog/release/node-v0-5-4.md new file mode 100644 index 00000000000..2dd02e12ad7 --- /dev/null +++ b/doc/blog/release/node-v0-5-4.md @@ -0,0 +1,36 @@ +version: 0.5.4 +title: Node v0.5.4 +author: ryandahl +date: Fri Aug 12 2011 08:38:26 GMT-0700 (PDT) +status: publish +category: release +slug: node-v0-5-4 + +2011.08.12, Version 0.5.4 (unstable) + +
  • libuv/Windows compatibility improvements + +
  • Build on Microsoft Visual Studio via GYP. Use generate-projects.bat in the to build sln files. (Peter Bright, Igor Zinkovsky) + +
  • Make Mikeal's HTTP agent client the default. Use old HTTP client with --use-http1 + +
  • Fixes https host header default port handling. (Mikeal Rogers) + +
  • #1440 strip byte order marker when loading *.js and *.json files (Ben Noordhuis) + +
  • #1434 Improve util.format() compatibility with browser. (Koichi Kobayashi) + +
  • Provide unchecked uint entry points for integer Buffer.read/writeInt methods. (Robert Mustacchi) + +
  • CMake improvements (Tom Huges) + +
  • Upgrade V8 to 3.5.4.
+ + +Download: http://nodejs.org/dist/v0.5.4/node-v0.5.4.tar.gz + +Windows Executable: http://nodejs.org/dist/v0.5.4/node.exe + +Website: http://nodejs.org/dist/v0.5.4/docs + +Documentation: http://nodejs.org/dist/v0.5.4/docs/api diff --git a/doc/blog/release/node-v0-5-5.md b/doc/blog/release/node-v0-5-5.md new file mode 100644 index 00000000000..886fac90ef0 --- /dev/null +++ b/doc/blog/release/node-v0-5-5.md @@ -0,0 +1,40 @@ +version: 0.5.5 +title: Node v0.5.5 +author: bennoordhuis +date: Fri Aug 26 2011 23:20:10 GMT-0700 (PDT) +status: publish +category: release +slug: node-v0-5-5 + +

2011.08.26, Version 0.5.5 (unstable)

+
    +
  • typed arrays, implementation from Plesk +
  • fix IP multicast on SunOS +
  • fix DNS lookup order: IPv4 first, IPv6 second (--use-uv only) +
  • remove support for UNIX datagram sockets (--use-uv only) +
  • UDP support for Windows (Bert Belder) +
  • #1572 improve tab completion for objects in the REPL (Nathan Rajlich) +
  • #1563 fix buffer overflow in child_process module (reported by Dean McNamee) +
  • #1546 fix performance regression in http module (reported by Brian Geffon) +
  • #1491 add PBKDF2 crypto support (Glen Low) +
  • #1447 remove deprecated http.cat() function (Mikeal Rogers) +
  • #1140 fix incorrect dispatch of vm.runInContext's filename argument
    + (Antranig Basman)

    +
  • #1140 document vm.runInContext() and vm.createContext() (Antranig Basman) +
  • #1428 fix os.freemem() on 64 bits freebsd (Artem Zaytsev) +
  • #1164 make all DNS lookups async, fixes uncatchable exceptions
    + (Koichi Kobayashi)

    +
  • fix incorrect ssl shutdown check (Tom Hughes) +
  • various cmake fixes (Tom Hughes) +
  • improved documentation (Koichi Kobayashi, Logan Smyth, Fedor Indutny,
    + Mikeal Rogers, Maciej Małecki, Antranig Basman, Mickaël Delahaye)

    +
  • upgrade libuv to commit 835782a +
  • upgrade V8 to 3.5.8 +
+

Download: http://nodejs.org/dist/node-v0.5.5.tar.gz

+

Windows Executable: http://nodejs.org/dist/v0.5.5/node.exe

+

Website: http://nodejs.org/docs/v0.5.5/

+

Documentation: http://nodejs.org/docs/v0.5.5/api/

+

+ +Update: The .exe has a bug that results in incompatibility with Windows XP and Server 2003. This has been reported in issue #1592 and fixed. A new binary was made that is compatibile with the older Windows: http://nodejs.org/dist/v0.5.5/node-186364e.exe. diff --git a/doc/blog/release/node-v0-5-6.md b/doc/blog/release/node-v0-5-6.md new file mode 100644 index 00000000000..ca1a392b013 --- /dev/null +++ b/doc/blog/release/node-v0-5-6.md @@ -0,0 +1,49 @@ +version: 0.5.6 +title: Node v0.5.6 (unstable) +author: piscisaureus +date: Fri Sep 09 2011 16:30:39 GMT-0700 (PDT) +status: publish +category: release +slug: node-v0-5-6 + +2011.09.08, Version 0.5.6 (unstable) +
    +
  • #345, #1635, #1648 Documentation improvements (Thomas Shinnick, Abimanyu Raja, AJ ONeal, Koichi Kobayashi, Michael Jackson, Logan Smyth, Ben Noordhuis)
  • +
  • #650 Improve path parsing on windows (Bert Belder)
  • +
  • #752 Remove headers sent check in OutgoingMessage.getHeader() (Peter Lyons)
  • +
  • #1236, #1438, #1506, #1513, #1621, #1640, #1647 Libuv-related bugs fixed (Jorge Chamorro Bieling, Peter Bright, Luis Lavena, Igor Zinkovsky)
  • +
  • #1296, #1612 crypto: Fix BIO's usage. (Koichi Kobayashi)
  • +
  • #1345 Correctly set socket.remoteAddress with libuv backend (Bert Belder)
  • +
  • #1429 Don't clobber quick edit mode on windows (Peter Bright)
  • +
  • #1503 Make libuv backend default on unix, override with `node --use-legacy`
  • +
  • #1565 Fix fs.stat for paths ending with \ on windows (Igor Zinkovsky)
  • +
  • #1568 Fix x509 certificate subject parsing (Koichi Kobayashi)
  • +
  • #1586 Make socket write encoding case-insensitive (Koichi Kobayashi)
  • +
  • #1591, #1656, #1657 Implement fs in libuv, remove libeio and pthread-win32 dependency on windows (Igor Zinkovsky, Ben Noordhuis, Ryan Dahl, Isaac Schlueter)
  • +
  • #1592 Don't load-time link against CreateSymbolicLink on windows (Peter Bright)
  • +
  • #1601 Improve API consistency when dealing with the socket underlying a HTTP client request (Mikeal Rogers)
  • +
  • #1610 Remove DigiNotar CA from trusted list (Isaac Schlueter)
  • +
  • #1617 Added some win32 os functions (Karl Skomski)
  • +
  • #1624 avoid buffer overrun with 'binary' encoding (Koichi Kobayashi)
  • +
  • #1633 make Buffer.write() always set _charsWritten (Koichi Kobayashi)
  • +
  • #1644 Windows: set executables to be console programs (Peter Bright)
  • +
  • #1651 improve inspection for sparse array (Koichi Kobayashi)
  • +
  • #1672 set .code='ECONNRESET' on socket hang up errors (Ben Noordhuis)
  • +
  • Add test case for foaf+ssl client certificate (Niclas Hoyer)
  • +
  • Added RPATH environment variable to override run-time library paths (Ashok Mudukutore)
  • +
  • Added TLS client-side session resumption support (Sean Cunningham)
  • +
  • Added additional properties to getPeerCertificate (Nathan Rixham, Niclas Hoyer)
  • +
  • Don't eval repl command twice when an error is thrown (Nathan Rajlich)
  • +
  • Improve util.isDate() (Nathan Rajlich)
  • +
  • Improvements in libuv backend and bindings, upgrade libuv to bd6066cb349a9b3a1b0d87b146ddaee06db31d10
  • +
  • Show warning when using lib/sys.js (Maciej Malecki)
  • +
  • Support plus sign in url protocol (Maciej Malecki)
  • +
  • Upgrade V8 to 3.6.2
  • +
+Download: http://nodejs.org/dist/v0.5.6/node-v0.5.6.tar.gz + +Windows Executable: http://nodejs.org/dist/v0.5.6/node.exe + +Website: http://nodejs.org/docs/v0.5.6/ + +Documentation: http://nodejs.org/docs/v0.5.6/api/ diff --git a/doc/blog/release/node-v0-5-7-unstable.md b/doc/blog/release/node-v0-5-7-unstable.md new file mode 100644 index 00000000000..1b640e7dbee --- /dev/null +++ b/doc/blog/release/node-v0-5-7-unstable.md @@ -0,0 +1,35 @@ +version: 0.5.7 +title: Node v0.5.7 (unstable) +author: ryandahl +date: Fri Sep 16 2011 18:57:03 GMT-0700 (PDT) +status: publish +category: release +slug: node-v0-5-7-unstable + +2011.09.16, Version 0.5.7 (unstable) +
    +
  • Upgrade V8 to 3.6.4 +
  • Improve Windows compatibility +
  • Documentation improvements +
  • Debugger and REPL improvements (Fedor Indutny) +
  • Add legacy API support: net.Stream(fd), process.stdout.writable, process.stdout.fd +
  • Fix mkdir EEXIST handling (isaacs) +
  • Use net_uv instead of net_legacy for stdio +
  • Do not load readline from util.inspect +
  • #1673 Fix bug related to V8 context with accessors (Fedor Indutny) +
  • #1634 util: Fix inspection for Error (koichik) +
  • #1645 fs: Add positioned file writing feature to fs.WriteStream (Thomas Shinnick) +
  • #1637 fs: Unguarded fs.watchFile cache statWatchers checking fixed (Thomas Shinnick) +
  • #1695 Forward customFds to ChildProcess.spawn +
  • #1707 Fix hasOwnProperty security problem in querystring (isaacs) +
  • #1719 Drain OpenSSL error queue
+ + + +Download: http://nodejs.org/dist/v0.5.7/node-v0.5.7.tar.gz + +Windows Executable: http://nodejs.org/dist/v0.5.7/node.exe + +Website: http://nodejs.org/docs/v0.5.7/ + +Documentation: http://nodejs.org/docs/v0.5.7/api/ diff --git a/doc/blog/release/node-v0-5-8.md b/doc/blog/release/node-v0-5-8.md new file mode 100644 index 00000000000..9f0fc146c3a --- /dev/null +++ b/doc/blog/release/node-v0-5-8.md @@ -0,0 +1,26 @@ +version: 0.5.8 +title: Node v0.5.8 +author: ryandahl +date: Fri Sep 30 2011 16:47:11 GMT-0700 (PDT) +status: publish +category: release +slug: node-v0-5-8 + +2011.09.30, Version 0.5.8 (unstable)
  • zlib bindings (isaacs) +
  • Windows supports TTY ANSI escape codes (Bert Belder) +
  • Debugger improvements (Fedor Indutny) +
  • crypto: look up SSL errors with ERR_print_errors() (Ben Noordhuis) +
  • dns callbacks go through MakeCallback now +
  • Raise an error when a malformed package.json file is found. (Ben Leslie) +
  • buffers: handle bad length argument in constructor (Ben Noordhuis) +
  • #1726, unref process.stdout +
  • Doc improvements (Ben Noordhuis, Fedor Indutny, koichik) +
  • Upgrade libuv to fe18438
+ +Download: http://nodejs.org/dist/v0.5.8/node-v0.5.8.tar.gz + +Windows Executable: http://nodejs.org/dist/v0.5.8/node.exe + +Website: http://nodejs.org/docs/v0.5.8/ + +Documentation: http://nodejs.org/docs/v0.5.8/api/ diff --git a/doc/blog/release/node-v0-5-9.md b/doc/blog/release/node-v0-5-9.md new file mode 100644 index 00000000000..6e361bcc4f8 --- /dev/null +++ b/doc/blog/release/node-v0-5-9.md @@ -0,0 +1,27 @@ +version: 0.5.9 +title: Node v0.5.9 +author: ryandahl +date: Mon Oct 10 2011 19:06:21 GMT-0700 (PDT) +status: publish +category: release +slug: node-v0-5-9 + +2011.10.10, Version 0.5.9 (unstable) +
  • fs.watch interface backed by kqueue, inotify, and ReadDirectoryChangesW (Igor Zinkovsky, Ben Noordhuis)
  • +
  • add dns.resolveTxt (Christian Tellnes)
  • +
  • Remove legacy http library (Ben Noordhuis)
  • +
  • child_process.fork returns and works on Windows. Allows passing handles. (Igor Zinkovsky, Bert Belder)
  • +
  • #1774 Lint and clean up for --harmony_block_scoping (Tyler Larson, Colton Baker)
  • +
  • #1813 Fix ctrl+c on Windows (Bert Belder)
  • +
  • #1844 unbreak --use-legacy (Ben Noordhuis)
  • +
  • process.stderr now goes through libuv. Both process.stdout and process.stderr are blocking when referencing a TTY.
  • +
  • net_uv performance improvements (Ben Noordhuis, Bert Belder)
+ + +Download: http://nodejs.org/dist/v0.5.9/node-v0.5.9.tar.gz + +Windows Executable: http://nodejs.org/dist/v0.5.9/node.exe + +Website: http://nodejs.org/docs/v0.5.9/ + +Documentation: http://nodejs.org/docs/v0.5.9/api/ diff --git a/doc/blog/release/node-v0-6-0.md b/doc/blog/release/node-v0-6-0.md new file mode 100644 index 00000000000..ea0e71373b5 --- /dev/null +++ b/doc/blog/release/node-v0-6-0.md @@ -0,0 +1,80 @@ +version: 0.6.0 +title: Node v0.6.0 +author: ryandahl +date: Sat Nov 05 2011 02:07:10 GMT-0700 (PDT) +status: publish +category: release +slug: node-v0-6-0 + +We are happy to announce the third stable branch of Node v0.6. We will be freezing JavaScript, C++, and binary interfaces for all v0.6 releases. + +The major differences between v0.4 and v0.6 are
    +
  • Native Windows support using I/O Completion Ports for sockets. +
  • Integrated load balancing over multiple processes. docs +
  • Better support for IPC between Node instances docs +
  • Improved command line debugger docs +
  • Built-in binding to zlib for compression docs +
  • Upgrade v8 from 3.1 to 3.6
+ +In order to support Windows we reworked much of the core architecture. There was some fear that our work would degrade performance on UNIX systems but this was not the case. Here is a Linux system we benched for demonstration: + + + + + +
v0.4.12 (linux)v0.6.0 (linux)
http_simple.js /bytes/1024 5461 r/s 6263 r/s
io.js read 19.75 mB/s 26.63 mB/s
io.js write 21.60 mB/s 17.40 mB/s
startup.js 74.7 ms 49.6 ms
+ +Bigger is better in http and io benchmarks, smaller is better in startup. The http benchmark was done with 600 clients on a 10GE network served from three load generation machines. + +In the last version of Node, v0.4, we could only run Node on Windows with Cygwin. Therefore we've gotten massive improvements by targeting the native APIs. Benchmarks on the same machine: + + + + + +
v0.4.12 (windows)v0.6.0 (windows)
http_simple.js /bytes/1024 3858 r/s 5823 r/s
io.js read 12.41 mB/s 26.51 mB/s
io.js write 12.61 mB/s 33.58 mB/s
startup.js 152.81 ms 52.04 ms
+ +We consider this a good intermediate stage for the Windows port. There is still work to be done. For example, we are not yet providing users with a blessed path for building addon modules in MS Visual Studio. Work will continue in later releases. + +For users upgrading code bases from v0.4 to v0.6 we've documented most of the issues that you will run into. Most people find the change painless. Despite the long list of changes most core APIs remain untouched. + +Our release cycle will be tightened dramatically now. Expect to see a new stable branch in January. We wish to eventually have our releases in sync with Chrome and V8's 6 week cycle. + +Thank you to everyone who contributed code, tests, docs, or sent in bug reports. + +Here are the changes between v0.5.12 and v0.6.0: + +2011.11.04, Version 0.6.0 (stable) +
  • print undefined on undefined values in REPL (Nathan Rajlich)
  • +
  • doc improvements (koichik, seebees, bnoordhuis, Maciej Małecki, Jacob Kragh)
  • +
  • support native addon loading in windows (Bert Belder)
  • +
  • rename getNetworkInterfaces() to networkInterfaces() (bnoordhuis)
  • +
  • add pending accepts knob for windows (igorzi)
  • +
  • http.request(url.parse(x)) (seebees)
  • +
  • #1929 zlib Respond to 'resume' events properly (isaacs)
  • +
  • stream.pipe: Remove resume and pause events
  • +
  • test fixes for windows (igorzi)
  • +
  • build system improvements (bnoordhuis)
  • +
  • #1936 tls: does not emit 'end' from EncryptedStream (koichik)
  • +
  • #758 tls: add address(), remoteAddress/remotePort
  • +
  • #1399 http: emit Error object after .abort() (bnoordhuis)
  • +
  • #1999 fs: make mkdir() default to 0777 permissions (bnoordhuis)
  • +
  • #2001 fix pipe error codes
  • +
  • #2002 Socket.write should reset timeout timer
  • +
  • stdout and stderr are blocking when associated with file too.
  • +
  • remote debugger support on windows (Bert Belder)
  • +
  • convenience methods for zlib (Matt Robenolt)
  • +
  • process.kill support on windows (igorzi)
  • +
  • process.uptime() support on windows (igorzi)
  • +
  • Return IPv4 addresses before IPv6 addresses from getaddrinfo
  • +
  • util.inspect improvements (Nathan Rajlich)
  • +
  • cluster module api changes
  • +
  • Downgrade V8 to 3.6.6.6
+ +Download: http://nodejs.org/dist/v0.6.0/node-v0.6.0.tar.gz + +Windows Executable: http://nodejs.org/dist/v0.6.0/node.exe + +Website: http://nodejs.org/docs/v0.6.0/ + +Documentation: http://nodejs.org/docs/v0.6.0/api/ diff --git a/doc/blog/release/node-v0-6-1.md b/doc/blog/release/node-v0-6-1.md new file mode 100644 index 00000000000..14a0db49529 --- /dev/null +++ b/doc/blog/release/node-v0-6-1.md @@ -0,0 +1,33 @@ +version: 0.6.1 +title: Node v0.6.1 +author: ryandahl +date: Fri Nov 11 2011 15:34:15 GMT-0800 (PST) +status: publish +category: release +slug: node-v0-6-1 + +2011.11.11, Version 0.6.1 (stable) +
  • doc improvements (Eric Lovett, Ben Noordhuis, Scott Anderson, Yoji SHIDARA)
  • +
  • crypto: make thread-safe (Ben Noordhuis)
  • +
  • fix process.kill error object
  • +
  • debugger: correctly handle source with multi-byte characters (Shigeki Ohtsu)
  • +
  • make stdout and stderr non-destroyable (Igor Zinkovsky)
  • +
  • fs: don't close uninitialized fs.watch handle (Ben Noordhuis)
  • +
  • #2026 fix man page install on BSDs (Ben Noordhuis)
  • +
  • #2040 fix unrecognized errno assert in uv_err_name
  • +
  • #2043 fs: mkdir() should call callback if mode is omitted
  • +
  • #2045 fs: fix fs.realpath on windows to return on error (Benjamin Pasero)
  • +
  • #2047 minor cluster improvements
  • +
  • #2052 readline get window columns correctly
  • +
  • Upgrade V8 to 3.6.6.7
+ + +Source Code: http://nodejs.org/dist/v0.6.1/node-v0.6.1.tar.gz + +Windows Installer: http://nodejs.org/dist/v0.6.1/node-v0.6.1.msi + +Macintosh Installer: http://nodejs.org/dist/v0.6.1/node-v0.6.1.pkg + +Website: http://nodejs.org/docs/v0.6.1/ + +Documentation: http://nodejs.org/docs/v0.6.1/api/ diff --git a/doc/blog/release/node-v0-6-10.md b/doc/blog/release/node-v0-6-10.md new file mode 100644 index 00000000000..a0ca4e4a37d --- /dev/null +++ b/doc/blog/release/node-v0-6-10.md @@ -0,0 +1,30 @@ +version: 0.6.10 +title: Node v0.6.10 +author: Isaac Schlueter +date: Thu Feb 02 2012 17:22:03 GMT-0800 (PST) +status: publish +category: release +slug: node-v0-6-10 + +

2012.02.02, Version 0.6.10 (stable)

+ +
    +
  • Update V8 to 3.6.6.20

  • +
  • Add npm msysgit bash shim to msi installer (isaacs)

  • +
  • buffers: fix intermittent out of bounds error (Ben Noordhuis)

  • +
  • buffers: honor length argument in base64 decoder (Ben Noordhuis)

  • +
  • windows: Fix path.exists regression (Bert Belder)

  • +
  • Make QueryString.parse run faster (Philip Tellis)

  • +
  • http: avoid freeing http-parser objects too early (koichik)

  • +
  • timers: add v0.4 compatibility hack (Ben Noordhuis)

  • +
  • Proper EPERM error code support (Igor Zinkovsky, Brandon Philips)

  • +
  • dgram: Implement udp multicast methods on windows (Bert Belder)

  • +

Source Code: http://nodejs.org/dist/v0.6.10/node-v0.6.10.tar.gz

+ +

Windows Installer: http://nodejs.org/dist/v0.6.10/node-v0.6.10.msi

+ +

Macintosh Installer: http://nodejs.org/dist/v0.6.10/node-v0.6.10.pkg

+ +

Website: http://nodejs.org/docs/v0.6.10/

+ +

Documentation: http://nodejs.org/docs/v0.6.10/api/

diff --git a/doc/blog/release/node-v0-6-2.md b/doc/blog/release/node-v0-6-2.md new file mode 100644 index 00000000000..b405268bc7b --- /dev/null +++ b/doc/blog/release/node-v0-6-2.md @@ -0,0 +1,27 @@ +version: 0.6.2 +title: Node v0.6.2 +author: bennoordhuis +date: Fri Nov 18 2011 15:35:32 GMT-0800 (PST) +status: publish +category: release +slug: node-v0-6-2 + +

2011.11.18, Version 0.6.2 (stable)

+
    +
  • doc improvements (Artur Adib, Trevor Burnham, Ryan Emery, Trent Mick)
  • +
  • timers: remember extra setTimeout() arguments when timeout==0
  • +
  • punycode: use Mathias Bynens's punycode library, it's more compliant
  • +
  • repl: improved tab completion (Ryan Emery)
  • +
  • buffer: fix range checks in .writeInt() functions (Lukasz Walukiewicz)
  • +
  • tls: make cipher list configurable
  • +
  • addons: make Buffer and ObjectWrap visible to Windows add-ons (Bert Belder)
  • +
  • crypto: add PKCS#1 a.k.a RSA public key verification support
  • +
  • windows: fix stdout writes when redirected to nul
  • +
  • sunos: fix build on Solaris and Illumos
  • +
  • Upgrade V8 to 3.6.6.8
  • +
+

Source Code: http://nodejs.org/dist/v0.6.2/node-v0.6.2.tar.gz

+

Windows Installer: http://nodejs.org/dist/v0.6.2/node-v0.6.2.msi

+

Macintosh Installer: http://nodejs.org/dist/v0.6.2/node-v0.6.2.pkg

+

Website: http://nodejs.org/docs/v0.6.2/

+

Documentation: http://nodejs.org/docs/v0.6.2/api/

diff --git a/doc/blog/release/node-v0-6-3.md b/doc/blog/release/node-v0-6-3.md new file mode 100644 index 00000000000..559c3d352a6 --- /dev/null +++ b/doc/blog/release/node-v0-6-3.md @@ -0,0 +1,30 @@ +version: 0.6.3 +title: Node v0.6.3 +author: piscisaureus +date: Fri Nov 25 2011 02:54:08 GMT-0800 (PST) +status: publish +category: release +slug: node-v0-6-3 + +2011.11.25, Version 0.6.3 (stable) +
    +
  • #2083 Land NPM in Node. It is included in packages/installers and installed on `make install`.
  • +
  • #2076 Add logos to windows installer.
  • +
  • #1711 Correctly handle http requests without headers. (Ben Noordhuis, Felix Geisendörfer)
  • +
  • TLS: expose more openssl SSL context options and constants. (Ben Noordhuis)
  • +
  • #2177 Windows: don't kill UDP socket when a packet fails to reach its destination. (Bert Belder)
  • +
  • Windows: support paths longer than 260 characters. (Igor Zinkovsky)
  • +
  • Windows: correctly resolve drive-relative paths. (Bert Belder)
  • +
  • #2166 Don't leave file descriptor open after lchmod. (Isaac Schlueter)
  • +
  • #2084 Add OS X .pkg build script to make file.
  • +
  • #2160 Documentation improvements. (Ben Noordhuis)
  • +
+Source Code: http://nodejs.org/dist/v0.6.3/node-v0.6.3.tar.gz + +Windows Installer: http://nodejs.org/dist/v0.6.3/node-v0.6.3.msi + +Macintosh Installer: http://nodejs.org/dist/v0.6.3/node-v0.6.3.pkg + +Website: http://nodejs.org/docs/v0.6.3/ + +Documentation: http://nodejs.org/docs/v0.6.3/api/ diff --git a/doc/blog/release/node-v0-6-4.md b/doc/blog/release/node-v0-6-4.md new file mode 100644 index 00000000000..f99f15fc594 --- /dev/null +++ b/doc/blog/release/node-v0-6-4.md @@ -0,0 +1,31 @@ +version: 0.6.4 +title: Node v0.6.4 +author: bennoordhuis +date: Thu Dec 01 2011 18:20:14 GMT-0800 (PST) +status: publish +category: release +slug: node-v0-6-4 + +2011.12.02, Version 0.6.4 (stable) +
    +
  • doc improvements (Kyle Young, Tim Oxley, Roman Shtylman, Mathias Bynens)
  • +
  • upgrade bundled npm (Isaac Schlueter)
  • +
  • polish Windows installer (Igor Zinkovsky, Isaac Schlueter)
  • +
  • punycode: upgrade to v0.2.1 (Mathias Bynens)
  • +
  • build: add --without-npm flag to configure script
  • +
  • sys: deprecate module some more, print stack trace if NODE_DEBUG=sys
  • +
  • cli: add -p switch, prints result of --eval
  • +
  • #1997: fix Blowfish ECB encryption and decryption (Ingmar Runge)
  • +
  • #2223: fix socket 'close' event being emitted twice
  • +
  • #2224: fix RSS memory usage > 4 GB reporting (Russ Bradberry)
  • +
  • #2225: fix util.inspect() object stringification bug (Nathan Rajlich)
  • +
+Source Code: http://nodejs.org/dist/v0.6.4/node-v0.6.4.tar.gz + +Windows Installer: http://nodejs.org/dist/v0.6.4/node-v0.6.4.msi + +Macintosh Installer: http://nodejs.org/dist/v0.6.4/node-v0.6.4.pkg + +Website: http://nodejs.org/docs/v0.6.4/ + +Documentation: http://nodejs.org/docs/v0.6.4/api/ diff --git a/doc/blog/release/node-v0-6-5.md b/doc/blog/release/node-v0-6-5.md new file mode 100644 index 00000000000..832da74148f --- /dev/null +++ b/doc/blog/release/node-v0-6-5.md @@ -0,0 +1,21 @@ +version: 0.6.5 +title: Node v0.6.5 +author: ryandahl +date: Sun Dec 04 2011 00:59:57 GMT-0800 (PST) +status: publish +category: release +slug: node-v0-6-5 + +2011.12.04, Version 0.6.5 (stable) +
  • npm workaround Windows antivirus software (isaacs) +
  • Upgrade V8 to 3.6.6.11
+ +Source Code: http://nodejs.org/dist/v0.6.5/node-v0.6.5.tar.gz + +Windows Installer: http://nodejs.org/dist/v0.6.5/node-v0.6.5.msi + +Macintosh Installer: http://nodejs.org/dist/v0.6.5/node-v0.6.5.pkg + +Website: http://nodejs.org/docs/v0.6.5/ + +Documentation: http://nodejs.org/docs/v0.6.5/api/ diff --git a/doc/blog/release/node-v0-6-6.md b/doc/blog/release/node-v0-6-6.md new file mode 100644 index 00000000000..c52169a15a7 --- /dev/null +++ b/doc/blog/release/node-v0-6-6.md @@ -0,0 +1,32 @@ +version: 0.6.6 +title: Node v0.6.6 +author: Isaac Schlueter +date: Thu Dec 15 2011 11:07:57 GMT-0800 (PST) +status: publish +category: release +slug: node-v0-6-6 + +2011.12.14, Version 0.6.6 (stable) + +
    +
  • npm update to 1.1.0-beta-4 (Isaac Z. Schlueter)
  • +
  • cli: fix output of --help (Ben Noordhuis)
  • +
  • new website
  • +
  • pause/resume semantics for stdin (Isaac Z. Schlueter)
  • +
  • Travis CI integration (Maciej Małecki)
  • +
  • child_process: Fix bug regarding closed stdin (Ben Noordhuis)
  • +
  • Enable upgrades in MSI. (Igor Zinkovsky)
  • +
  • net: Fixes memory leak (Ben Noordhuis)
  • +
  • fs: handle fractional or NaN ReadStream buffer size (Ben Noordhuis)
  • +
  • crypto: fix memory leaks in PBKDF2 error path (Ben Noordhuis)
  • +
+ +Source Code: http://nodejs.org/dist/v0.6.6/node-v0.6.6.tar.gz + +Windows Installer: http://nodejs.org/dist/v0.6.6/node-v0.6.6.msi + +Macintosh Installer: http://nodejs.org/dist/v0.6.6/node-v0.6.6.pkg + +Website: http://nodejs.org/docs/v0.6.6/ + +Documentation: http://nodejs.org/docs/v0.6.6/api/ diff --git a/doc/blog/release/node-v0-6-7.md b/doc/blog/release/node-v0-6-7.md new file mode 100644 index 00000000000..0346f51c0c5 --- /dev/null +++ b/doc/blog/release/node-v0-6-7.md @@ -0,0 +1,41 @@ +version: 0.6.7 +title: Node v0.6.7 +author: Isaac Schlueter +date: Fri Jan 06 2012 17:54:49 GMT-0800 (PST) +status: publish +category: release +slug: node-v0-6-7 + +

2012.01.06, Version 0.6.7 (stable)

+ +
    +
  • V8 hash collision fix (Breaks MIPS) (Bert Belder, Erik Corry)

  • +
  • Upgrade V8 to 3.6.6.15

  • +
  • Upgrade npm to 1.1.0-beta-10 (isaacs)

  • +
  • many doc updates (Ben Noordhuis, Jeremy Martin, koichik, Dave Irvine, +Seong-Rak Choi, Shannen, Adam Malcontenti-Wilson, koichik)

  • +
  • Fix segfault in node_http_parser.cc

  • +
  • dgram, timers: fix memory leaks (Ben Noordhuis, Yoshihiro Kikuchi)

  • +
  • repl: fix repl.start not passing the ignoreUndefined arg (Damon Oehlman)

  • +
  • #1980: Socket.pause null reference when called on a closed Stream (koichik)

  • +
  • #2263: XMLHttpRequest piped in a writable file stream hang (koichik)

  • +
  • #2069: http resource leak (koichik)

  • +
  • buffer.readInt global pollution fix (Phil Sung)

  • +
  • timers: fix performance regression (Ben Noordhuis)

  • +
  • #2308, #2246: node swallows openssl error on request (koichik)

  • +
  • #2114: timers: remove _idleTimeout from item in .unenroll() (James Hartig)

  • +
  • #2379: debugger: Request backtrace w/o refs (Fedor Indutny)

  • +
  • simple DTrace ustack helper (Dave Pacheco)

  • +
  • crypto: rewrite HexDecode without snprintf (Roman Shtylman)

  • +
  • crypto: don’t ignore DH init errors (Ben Noordhuis)

  • +
+ +

Source Code: http://nodejs.org/dist/v0.6.7/node-v0.6.7.tar.gz

+ +

Windows Installer: http://nodejs.org/dist/v0.6.7/node-v0.6.7.msi

+ +

Macintosh Installer: http://nodejs.org/dist/v0.6.7/node-v0.6.7.pkg

+ +

Website: http://nodejs.org/docs/v0.6.7/

+ +

Documentation: http://nodejs.org/docs/v0.6.7/api/

diff --git a/doc/blog/release/node-v0-6-8.md b/doc/blog/release/node-v0-6-8.md new file mode 100644 index 00000000000..55de31eb6b1 --- /dev/null +++ b/doc/blog/release/node-v0-6-8.md @@ -0,0 +1,31 @@ +version: 0.6.8 +title: Node v0.6.8 +author: Isaac Schlueter +date: Thu Jan 19 2012 19:59:53 GMT-0800 (PST) +status: publish +category: release +slug: node-v0-6-8 + +

2012.01.19, Version 0.6.8 (stable)

+ +
    +
  • Update V8 to 3.6.6.19

  • +
  • Numeric key hash collision fix for V8 (Erik Corry, Fedor Indutny)

  • +
  • Add missing TTY key translations for F1-F5 on Windows (Brandon Benvie)

  • +
  • path.extname bugfix with . and .. paths (Bert Belder)

  • +
  • cluster: don't always kill the master on uncaughtException (Ben Noordhuis)

  • +
  • Update npm to 1.1.0-2 (isaacs)

  • +
  • typed arrays: set class name (Ben Noordhuis)

  • +
  • zlib binding cleanup (isaacs, Bert Belder)

  • +
  • dgram: use slab memory allocator (Michael Bernstein)

  • +
  • fix segfault #2473

  • +
  • #2521 60% improvement in fs.stat on Windows (Igor Zinkovsky)

  • +

Source Code: http://nodejs.org/dist/v0.6.8/node-v0.6.8.tar.gz

+ +

Windows Installer: http://nodejs.org/dist/v0.6.8/node-v0.6.8.msi

+ +

Macintosh Installer: http://nodejs.org/dist/v0.6.8/node-v0.6.8.pkg

+ +

Website: http://nodejs.org/docs/v0.6.8/

+ +

Documentation: http://nodejs.org/docs/v0.6.8/api/

diff --git a/doc/blog/release/node-v0-6-9.md b/doc/blog/release/node-v0-6-9.md new file mode 100644 index 00000000000..05d992febdd --- /dev/null +++ b/doc/blog/release/node-v0-6-9.md @@ -0,0 +1,30 @@ +version: 0.6.9 +title: Node v0.6.9 +author: Isaac Schlueter +date: Fri Jan 27 2012 16:58:18 GMT-0800 (PST) +status: publish +category: release +slug: node-v0-6-9 + +

2012.01.27, Version 0.6.9 (stable)

+ +
    +
  • +

    dgram: Bring back missing functionality for Unix (Dan VerWeire, +Roman Shtylman, Ben Noordhuis)

    +

    - Note: Windows UDP support not yet complete.

  • +
  • http: Fix parser memory leak (koichik)

  • +
  • zlib: Fix #2365 crashes on invalid input (Nicolas LaCasse)

  • +
  • module: fix --debug-brk on symlinked scripts (Fedor Indutny)

  • +
  • Documentation Restyling (Matthew Fitzsimmons)

  • +
  • Update npm to 1.1.0-3 (isaacs)

  • +
  • Windows: fix regression in stat() calls to C:\ (Bert Belder)

  • +

Source Code: http://nodejs.org/dist/v0.6.9/node-v0.6.9.tar.gz

+ +

Windows Installer: http://nodejs.org/dist/v0.6.9/node-v0.6.9.msi

+ +

Macintosh Installer: http://nodejs.org/dist/v0.6.9/node-v0.6.9.pkg

+ +

Website: http://nodejs.org/docs/v0.6.9/

+ +

Documentation: http://nodejs.org/docs/v0.6.9/api/

diff --git a/doc/blog/release/node-v0-7-0-unstable.md b/doc/blog/release/node-v0-7-0-unstable.md new file mode 100644 index 00000000000..3036b9228f8 --- /dev/null +++ b/doc/blog/release/node-v0-7-0-unstable.md @@ -0,0 +1,29 @@ +version: 0.7.0 +title: Node v0.7.0 (Unstable) +author: ryandahl +date: Mon Jan 16 2012 19:58:28 GMT-0800 (PST) +status: publish +category: release +slug: node-v0-7-0-unstable + +This is the first release in the unstable v0.7 series. Almost all users will want to remain using the stable v0.6 releases. + +2012.01.16, Version 0.7.0 (unstable) +
    +
  • Upgrade V8 to 3.8.6 +
  • Use GYP build system on unix (Ben Noordhuis) +
  • Experimenetal isolates support (Ben Noordhuis) +
  • Improvements to Cluster API (Andreas Madsen) +
  • Use isolates for internal debugger (Fedor Indutny) +
  • Bug fixes
+ + +Source Code: http://nodejs.org/dist/v0.7.0/node-v0.7.0.tar.gz + +Windows Installer: http://nodejs.org/dist/v0.7.0/node-v0.7.0.msi + +Macintosh Installer: http://nodejs.org/dist/v0.7.0/node-v0.7.0.pkg + +Website: http://nodejs.org/docs/v0.7.0/ + +Documentation: http://nodejs.org/docs/v0.7.0/api/ diff --git a/doc/blog/release/node-v0-7-1.md b/doc/blog/release/node-v0-7-1.md new file mode 100644 index 00000000000..efb89d045dc --- /dev/null +++ b/doc/blog/release/node-v0-7-1.md @@ -0,0 +1,30 @@ +version: 0.7.1 +title: Node v0.7.1 +author: Isaac Schlueter +date: Mon Jan 23 2012 17:35:59 GMT-0800 (PST) +status: publish +category: release +slug: node-v0-7-1 + +

2012.01.23, Version 0.7.1 (unstable)

+ +
    +
  • Update V8 to 3.8.8

  • +
  • Install node-waf by default (Fedor Indutny)

  • +
  • crypto: Add ability to turn off PKCS padding (Ingmar Runge)

  • +
  • v8: implement VirtualMemory class on SunOS (Ben Noordhuis)

  • +
  • Add cluster.setupMaster (Andreas Madsen)

  • +
  • move path.exists* to fs.exists* (Maciej Małecki)

  • +
  • typed arrays: set class name (Ben Noordhuis)

  • +
  • libuv bug fixes (Igor Zinkovsky, Ben Noordhuis, Dan VerWeire)

  • +
+ +

Source: http://nodejs.org/dist/v0.7.1/node-v0.7.1.tar.gz

+ +

Windows Installer: http://nodejs.org/dist/v0.7.1/node-v0.7.1.msi

+ +

Macintosh Installer: http://nodejs.org/dist/v0.7.1/node-v0.7.1.pkg

+ +

Website: http://nodejs.org/docs/v0.7.1/

+ +

Documentation: http://nodejs.org/docs/v0.7.1/api/

diff --git a/doc/blog/release/node-v0-7-2-unstable.md b/doc/blog/release/node-v0-7-2-unstable.md new file mode 100644 index 00000000000..d5c1f8fb820 --- /dev/null +++ b/doc/blog/release/node-v0-7-2-unstable.md @@ -0,0 +1,32 @@ +version: 0.7.2 +title: Node v0.7.2 (unstable) +author: Isaac Schlueter +date: Wed Feb 01 2012 13:13:04 GMT-0800 (PST) +status: publish +category: release +slug: node-v0-7-2-unstable + +

2012.02.01, Version 0.7.2 (unstable)

+ +
    +
  • Update V8 to 3.8.9

  • +
  • Support for sharing streams across Isolates (Igor Zinkovsky)

  • +
  • #2636 - Fix case where http_parsers are freed too early (koichik)

  • +
  • url: Support for IPv6 addresses in URLs (Łukasz Walukiewicz)

  • +
  • child_process: Add disconnect() method to child processes (Andreas Madsen)

  • +
  • fs: add O_EXCL support, exclusive open file (Ben Noordhuis)

  • +
  • fs: more specific error messages (Tj Holowaychuk)

  • +
  • tty: emit 'unknown' key event if key sequence not found (Dan VerWeire, Nathan Rajlich)

  • +
  • build: compile release build too if BUILDTYPE=Debug (Ben Noordhuis)

  • +
  • module: fix --debug-brk on symlinked scripts (Fedor Indutny)

  • +
  • zlib: fix Failed to set dictionary issue (Fedor Indutny)

  • +
  • waf: predict target arch for OS X (Fedor Indutny)

  • +

Source Code: http://nodejs.org/dist/v0.7.2/node-v0.7.2.tar.gz

+ +

Windows Installer: http://nodejs.org/dist/v0.7.2/node-v0.7.2.msi

+ +

Macintosh Installer: http://nodejs.org/dist/v0.7.2/node-v0.7.2.pkg

+ +

Website: http://nodejs.org/docs/v0.7.2/

+ +

Documentation: http://nodejs.org/docs/v0.7.2/api/

diff --git a/doc/blog/release/node-v0-7-3.md b/doc/blog/release/node-v0-7-3.md new file mode 100644 index 00000000000..a0d93df12d4 --- /dev/null +++ b/doc/blog/release/node-v0-7-3.md @@ -0,0 +1,39 @@ +version: 0.7.3 +title: Node v0.7.3 (unstable) +author: Isaac Schlueter +date: Tue Feb 07 2012 17:08:27 GMT-0800 (PST) +status: publish +category: release +slug: node-v0-7-3 + +

2012.02.07, Version 0.7.3 (unstable) + +

+
    +
  • Upgrade V8 to 3.9.2

    +
  • +
  • Revert support for isolates. (Ben Noordhuis)

    +
  • +
  • cluster: Cleanup docs, event handling, and process.disconnect (Andreas Madsen)

    +
  • +
  • gyp_addon: link with node.lib on Windows (Nathan Rajlich)

    +
  • +
  • http: fix case where http-parser is freed twice (koichik)

    +
  • +
  • Windows: disable RTTI and exceptions (Bert Belder)

    +
  • +
+

Source Code: http://nodejs.org/dist/v0.7.3/node-v0.7.3.tar.gz + +

+

Windows Installer: http://nodejs.org/dist/v0.7.3/node-v0.7.3.msi + +

+

Macintosh Installer: http://nodejs.org/dist/v0.7.3/node-v0.7.3.pkg + +

+

Website: http://nodejs.org/docs/v0.7.3/ + +

+

Documentation: http://nodejs.org/docs/v0.7.3/api/ +

diff --git a/doc/blog/release/node-v0.8.0.md b/doc/blog/release/node-v0.8.0.md new file mode 100644 index 00000000000..118668fc923 --- /dev/null +++ b/doc/blog/release/node-v0.8.0.md @@ -0,0 +1,384 @@ +title: Node v0.8.0 +date: Mon Jun 25 2012 09:00:00 GMT-0700 (PDT) +version: 0.8.0 +category: release +author: Isaac Z. Schlueter +slug: node-v0-8-0 +status: publish + +I am thrilled to announce the arrival of a new stable version of +Node.js. + +Compared with the v0.6 releases of Node, this release brings significant +improvements in many key performance metrics, as well as +cleanup in several core APIs, and the addition of new debugging +features. + +## tl;dr + +With version 0.8.0: + +1. Node got a lot faster. +2. Node got more stable. +3. You can do stuff with file descriptors again. +4. The [cluster module](http://nodejs.org/api/cluster.html) is much more + awesome. +5. The [domain module](http://nodejs.org/api/domain.html) was added. +6. The repl is better. +7. The build system changed from waf to gyp. +8. [Some other stuff changed, + too.](https://github.com/joyent/node/wiki/API-changes-between-v0.6-and-v0.8) +9. Scroll to the bottom for the links to install it. + +## Performance + +This version brings a few key enhancements in V8 and libuv that result +in significantly improved throughput. + +All of these benchmarks were run on my OS X laptop, but the results are +typical of what we're seeing on SmartOS, Linux, and Windows. + +``` +# io.js + +# 0.6.19, writes +Wrote 1024 byte buffers: 19.428793471925395 mB/s +Wrote 4096 byte buffers: 59.737156511350065 mB/s +Wrote 16384 byte buffers: 83.97010664203543 mB/s +Wrote 65536 byte buffers: 97.4184120798831 mB/s + +# 0.8.0, writes +Wrote 1024 byte buffers: 61.236987140232706 mB/s +215.19% +Wrote 4096 byte buffers: 109.05125408942203 mB/s +82.55% +Wrote 16384 byte buffers: 182.18254691200585 mB/s +116.96% +Wrote 65536 byte buffers: 181.91740949608877 mB/s +86.74% + +# v0.6.19, reads +Read 1024 byte buffers: 29.96883241428914 mB/s +Read 4096 byte buffers: 62.34413965087282 mB/s +Read 16384 byte buffers: 165.7550140891762 mB/s +Read 65536 byte buffers: 266.73779674579885 mB/s + +# v0.8.0, reads +Read 1024 byte buffers: 57.63688760806916 mB/s +92.32% +Read 4096 byte buffers: 136.7801942278758 mB/s +119.40% +Read 16384 byte buffers: 244.8579823702253 mB/s +47.72% +Read 65536 byte buffers: 302.2974607013301 mB/s +13.33% +``` + +The difference is not small. If you are writing network programs with +node, and pushing a lot of traffic, you will notice this improvement. + +The speed of reading files got quite a bit faster as well: + +``` +# v0.6.19 +read the file 110948 times (higher is better) +90141.32 ns per read (lower is better) +11093.69 reads per sec (higher is better) + +# v0.8.0 +read the file 158193 times (higher is better) +42.58% +63217.16 ns per read (lower is better) -29.87% +15818.48 reads per sec (higher is better) +42.59% +``` + +And of course, the ubiquitous 'hello, world' http server benchmark got +significantly faster, especially for large message sizes: + +``` +$ TYPE=bytes LENGTH=123 bash benchmark/http.sh 2>&1 | grep Req +# 0.6.19 +Requests per second: 3317.24 [#/sec] (mean) +# 0.8.0 +Requests per second: 3795.34 [#/sec] (mean) +14.41% + + +$ TYPE=bytes LENGTH=1024 bash benchmark/http.sh 2>&1 | grep Req +# v0.6.19 +Requests per second: 3258.42 [#/sec] (mean) +# 0.8.0 +Requests per second: 3585.62 [#/sec] (mean) +10.04% + + +$ TYPE=bytes LENGTH=123456 bash benchmark/http.sh 2>&1 | grep Req +# v0.6.19 +Requests per second: 218.51 [#/sec] (mean) +# 0.8.0 +Requests per second: 749.17 [#/sec] (mean) +242.85% +``` + +The difference with Unicode responses is even more pronounced: + +``` +$ TYPE=unicode LENGTH=1024 bash benchmark/http.sh 2>&1 | grep Req +# v0.6.19 +Requests per second: 3228.23 [#/sec] (mean) +# v0.8.0 +Requests per second: 3317.60 [#/sec] (mean) +2.77% + +$ TYPE=unicode LENGTH=12345 bash benchmark/http.sh 2>&1 | grep Req +# v0.6.19 +Requests per second: 1703.96 [#/sec] (mean) +# v0.8.0 +Requests per second: 2431.61 [#/sec] (mean) +42.70% + +$ TYPE=unicode LENGTH=55555 bash benchmark/http.sh 2>&1 | grep Req +#v0.6.19 +Requests per second: 161.65 [#/sec] (mean) +#v0.8.0 +Requests per second: 980.38 [#/sec] (mean) +506.48% + +$ TYPE=unicode LENGTH=99999 bash benchmark/http.sh 2>&1 | grep Req +# v0.6.19 +^C # lost patience after a few hours +# v0.8.0 +Requests per second: 252.69 [#/sec] (mean) +``` + +The more bytes you're pushing, and the more work you're doing, the more +win you'll see with node 0.8 over 0.6. + +The vast majority of the performance boost is due to improvements in V8. +They've been very responsive to the needs of the Node.js project. A lot +of Node's success is due to being built on such a stellar VM. + + +## Build System + +Since its inception Node has used the WAF build system which is a Python +based system similar to SCons. The Chrome project recently changed to +the GYP meta-build system from SCons. GYP generates Makefiles, Visual +Studio project files, or XCode files depending on the target. V8, being +part of the Chrome project, now defines its build in GYP. By using GYP, +Node is able to: + +- integrate with the optimal build system on all platforms, +- easily able to integrate V8's build process into its own, and +- define its compilation declaratively for better manageability + +GYP was used already in Node v0.6 to build on Windows, but now it +defines the build on all platforms. Node is still in the process of +migrating external addon modules to GYP, and node-gyp is included with +npm. In future releases, node-waf will be officially deprecated. If +you are currently using a wscript in your addon, please migrate to gyp +as soon as possible. + + +## Stabler + +The transition from libev and libeio to libuv in 0.6 was somewhat +destabilizing for many node internals. The gambit paid off: libuv is +the obvious choice in cross-platform asynchronous IO libraries, and +Node.js is impressively performant on both Windows and Unix. But it +made the transition from 0.4 to 0.6 was very rocky for a lot of users. +Libuv wasn't as mature as node, and it showed in those early releases. + +At this point, with very few exceptions, if your v0.6 program doesn't +run on v0.8, it should be easy and obvious to make whatever changes are +necessary. Libuv has come a very long way, and Node 0.8 is a simpler +and more efficient machine as a result. + +See the [migration +wiki](https://github.com/joyent/node/wiki/API-changes-between-v0.6-and-v0.8) +for details on the specific APIs that changed. + +## The Return of File Descriptors + +In Node 0.4, there was a `listenFD` method that servers could use to +listen on a specific file descriptor that was already bound to a socket +or port. In 0.6, that functionality went away, largely because it was +very Unix-specific, and couldn't be easily made to work with the new +cross-platform libuv base. + +Since the most common use case for listenFD was as a method for having +servers in multiple node processes share the same underlying handle, the +`cluster` module was added in its place. However, this still left a lot +of use cases unaddressed, and was a reason why some people could not use +node 0.6 for their programs. + +In 0.8, we've replaced this functionality, as `server.listen({ fd: +number })`. + +The other feature in node 0.4 that got dropped in 0.6 was the ability to +pass arbitrary file descriptors as a child process's stdio, using the +`customFds` array. In Node 0.6, `customFds` could be used to inherit +the parent's stdio handles, but not to pass arbitrary handles or file +descriptors to the child's stdio. Also, there was never a way to pass +more than the standard `in, out, err` trio, so programs that expected +FD 4 to be opened in some specific way were out of luck. + +In 0.8, we've added the `stdio` array on the `child_process.spawn` +options. Pass as many file descriptors, handles, etc. as you like, and +the child process will see them as already-opened FDs. + +## More Powerful Cluster + +The cluster module in 0.8 is so much improved over 0.6, it's basically a +complete rewrite. The API is mostly backwards compatible, but not +entirely. (See the [migration +wiki](https://github.com/joyent/node/wiki/API-changes-between-v0.6-and-v0.8) +for details.) + +Barring these very minor API changes, if you were using cluster in 0.6, +then your program will still work, but it'll be faster and more +well-behaved now. And if you aren't taking advantage of the new +features in 0.8's cluster, you're really missing out. + +There's too much even to do it justice here. Go read [the API +docs](http://nodejs.org/api/cluster.html). + +## Domains + +The original idea for Domains was a way to join multiple different IO +actions, so that you can have some context when an error occurs. + +Since Ryan discussed the feature with node users at NodeConf Summer Camp +last year, the domains feature has gone through many revisions. The +problem is fairly well understood, but most attempts to solve it +resulted in serious performance regressions, or uncovered difficult edge +cases. + +What we ended up with in 0.8 is a very stripped-down version of this +idea. It's entirely opt-in, with minimal performance impact when it's +used (and none when it isn't). There are a lot of examples in [the API +documentation](http://nodejs.org/api/domain.html), so check them out, +and start handling your crashes smarter. + +The domain module is still experimental. We are looking forward to your +feedback, so please use it and let us know what you think. + +## Repl, Readline, TTY + +The Repl, Readline, and TTY modules have all had a major facelift. The +interfaces between these three modules are cleaned up and refactored, +removing a lot of common pain points and making it easier to use for +debugging your programs. + +It may seem minor at times, but a good repl dramatically increases the +quality of the overall experience. My personal favorites are: + +1. Typing `fs` or `net` or `path` will automatically load the module. +2. Typing `npm install ...` will give you a helpful message. +3. It doesn't do that stupid thing where long lines wrap and then the + backspace makes it get all confused and crazy. Instead of that, it + does the right thing. + +## Looking Forward + +Like other even-numbered version families before it, v0.8 will maintain +API and ABI stability throughout its lifetime. + +The v0.6 release family will continue to see releases for critical +bugfixes and security issues through the end of 2012. However, it will +not be the main focus of the core team's attention. + +The v0.9 releases will start in the next couple weeks. The main focus +of v0.9 will be: + +* The HTTP implementation - It has seen a lot of real-world use now, but + the http module is in dire need of a cleanup and refactor. Special + attention will be paid to making the interfaces more consistent, + improve performance, and increase correctness in more edge cases. +* The Streams API - The concept of the Stream API is very core to node. + However, it is also (like HTTP) a feature that grew up organically, + and is now in need of a cleanup. It is currently too hard to get + right, especially regarding error handling. +* Libuv Streams - The handle interfaces in libuv are going to be + refactored for added consistency throughout the codebase and across + platforms. + +Looking past that, there are a few areas where Node.js still has room +for improvement in terms of internal consistency, idiomatic JavaScript +usage, and performance. None of these are fully-fleshed out ideas yet, +but these are some of the items on our radar: + +* We ought to move to TypedArrays in favor of Buffers. Buffers will + continue to work, but since TypedArray is a JavaScript native, it + makes sense to move towards that as the preferred API. +* SSL performance leaves much to be desired at the moment. Node's + interface with OpenSSL is somewhat naive and leaves a lot of potential + optimization on the table. +* The VM module needs massive improvement. It lacks features required + to emulate a web browser JavaScript context, which means that it is + inadequate. +* The Crypto module still uses some very dated APIs. In 0.8, it can + accept Buffers for many things (finally!) but it still does not + present a Node-like streaming interface. + +At this point, the scope of Node's feature set is pretty much locked +down. We may move things around internally for these cleanup tasks, but +as you can see, there are no major new features planned. We've drawn +our boundaries, and now it's time to continue focusing on improving +stability and performance of the core, so that more innovation can +happen in **your** programs. + +And now, for those of you who may be wondering what was added since +v0.7.12, your regularly scheduled release announcement: + +## 2012.06.25, Version 0.8.0 (stable) + +* V8: upgrade to v3.11.10.10 + +* npm: Upgrade to 1.1.32 + +* Deprecate iowatcher (Ben Noordhuis) + +* windows: update icon (Bert Belder) + +* http: Hush 'MUST NOT have a body' warnings to debug() (isaacs) + +* Move blog.nodejs.org content into repository (isaacs) + +* Fix #3503: stdin: resume() on pipe(dest) (isaacs) + +* crypto: fix error reporting in SetKey() (Fedor Indutny) + +* Add --no-deprecation and --trace-deprecation command-line flags (isaacs) + +* fs: fix fs.watchFile() (Ben Noordhuis) + +* fs: Fix fs.readfile() on pipes (isaacs) + +* Rename GYP variable node_use_system_openssl to be consistent (Ryan Dahl) + + +Source Code: http://nodejs.org/dist/v0.8.0/node-v0.8.0.tar.gz + +Macintosh Installer (Universal): http://nodejs.org/dist/v0.8.0/node-v0.8.0.pkg + +Windows Installer: http://nodejs.org/dist/v0.8.0/node-v0.8.0-x86.msi + +Windows x64 Installer: http://nodejs.org/dist/v0.8.0/x64/node-v0.8.0-x64.msi + +Windows x64 Files: http://nodejs.org/dist/v0.8.0/x64/ + +Other release files: http://nodejs.org/dist/v0.8.0/ + +Website: http://nodejs.org/docs/v0.8.0/ + +Documentation: http://nodejs.org/docs/v0.8.0/api/ + +Shasums: + +``` +b92208b291ad420025c65661a7df51fc618e21ca license.rtf +0786bcda79bd651b9981682527a1bbabe0250700 node-v0.8.0-x86.msi +8f160a742a01fdfc1b1423b3fc742d184f1ab70c node-v0.8.0-x86.wixpdb +6035d6d59304add21e462cd7eb89491570b4970d node-v0.8.0.pkg +5171fb46fbfee5ac7129c4b17207a3f35a1f57e8 node-v0.8.0.tar.gz +742100a4ee4cd4d190031a30d9b22b2b69b6872e node.exe +52d20d285e9aec53043af0843f5ecc4153210693 node.exp +6d67a64274d844548cc6099c76181a50feafc233 node.lib +aa2af08d5ab869e6c8b67f01ed67129c1cad8bce node.pdb +b92208b291ad420025c65661a7df51fc618e21ca x64/license.rtf +c4d4164d4f78ea68e0e2a85b96f9b355f3b1df8b x64/node-v0.8.0-x64.msi +df8bb178ee4cb9562d93fe80bbe59b2acf1b9e6b x64/node-v0.8.0-x64.wixpdb +fc07b475d943f7681e1904d6d7d666b41874a6fa x64/node.exe +895002806dfb6d5bb141ef0f43cad3b540a4ff6c x64/node.exp +686c60d5ae5dad7fcffcdc88049c63b2cd23cffc x64/node.lib +75549cffab0c11107348a66ab0d94d4897bd6a27 x64/node.pdb +``` + +Edited by Tim Oxley to provide percentage differences in the +benchmarks. diff --git a/doc/blog/release/node-version-0-6-19-stable.md b/doc/blog/release/node-version-0-6-19-stable.md new file mode 100644 index 00000000000..3a29556c578 --- /dev/null +++ b/doc/blog/release/node-version-0-6-19-stable.md @@ -0,0 +1,61 @@ +version: 0.6.19 +title: Node Version 0.6.19 (stable) +author: Isaac Schlueter +date: Wed Jun 06 2012 09:55:37 GMT-0700 (PDT) +status: publish +category: release +slug: node-version-0-6-19-stable + +

2012.06.06 Version 0.6.19 (stable) + +

+
    +
  • npm: upgrade to 1.1.24

    +
  • +
  • fs: no end emit after createReadStream.pause() (Andreas Madsen)

    +
  • +
  • vm: cleanup module memory leakage (Marcel Laverdet)

    +
  • +
  • unix: fix loop starvation under high network load (Ben Noordhuis)

    +
  • +
  • unix: remove abort() in ev_unref() (Ben Noordhuis)

    +
  • +
  • windows/tty: never report error after forcibly aborting line-buffered read (Bert Belder)

    +
  • +
  • windows: skip GetFileAttributes call when opening a file (Bert Belder)

    +
  • +
+

Source Code: http://nodejs.org/dist/v0.6.19/node-v0.6.19.tar.gz + +

+

Windows Installer: http://nodejs.org/dist/v0.6.19/node-v0.6.19.msi + +

+

Windows x64 Files: http://nodejs.org/dist/v0.6.19/x64/ + +

+

Macintosh Installer (Universal): http://nodejs.org/dist/v0.6.19/node-v0.6.19.pkg + +

+

Other release files: http://nodejs.org/dist/v0.6.19/ + +

+

Website: http://nodejs.org/docs/v0.6.19/ + +

+

Documentation: http://nodejs.org/docs/v0.6.19/api/ +

+ +

Shasums:

+
ef4f5c1e5f12f6ef3478a794d6a81f59669332f9  node-v0.6.19.msi
+781616f33208f532f168633758a648c20e1ea68b  node-v0.6.19.pkg
+f6c5cfbadff4788ac3a95f8263a0c2f4e07444b6  node-v0.6.19.tar.gz
+10f729ca236825821d97556441fa64f994cb4ca8  node.exe
+5b8cd02e5f92ed6512aabdac11766ad8c1abc436  node.exp
+20037e4901de605e08e48d0c85531334912844e3  node.lib
+c44f62852918d449850014d9b29dd073cb6920a5  node.pdb
+04db25c93c5357394941dd2de12cb61959eb82d1  x64/node-v0.6.19.msi
+f77c77f2e470cfc9071853af2f277ba91d660b9c  x64/node.exe
+fcf26a3f984a3f19804e0567414604b77b1d3bac  x64/node.exp
+bfed2a24f253dbac99379d6f22fc8e9e85ade7ed  x64/node.lib
+95226c1cc5170ea05c2e54431040f06c3e95e99f  x64/node.pdb
diff --git a/doc/blog/release/node-version-0-7-9-unstable.md b/doc/blog/release/node-version-0-7-9-unstable.md new file mode 100644 index 00000000000..cb077d62582 --- /dev/null +++ b/doc/blog/release/node-version-0-7-9-unstable.md @@ -0,0 +1,73 @@ +version: 0.7.9 +title: Node Version 0.7.9 (unstable) +author: Isaac Schlueter +date: Tue May 29 2012 10:11:45 GMT-0700 (PDT) +status: publish +category: release +slug: node-version-0-7-9-unstable + +

2012.05.28, Version 0.7.9 (unstable) + +

+
    +
  • Upgrade V8 to 3.11.1

    +
  • +
  • Upgrade npm to 1.1.23

    +
  • +
  • uv: rework reference counting scheme (Ben Noordhuis)

    +
  • +
  • uv: add interface for joining external event loops (Bert Belder)

    +
  • +
  • repl, readline: Handle Ctrl+Z and SIGCONT better (Nathan Rajlich)

    +
  • +
  • fs: 64bit offsets for fs calls (Igor Zinkovsky)

    +
  • +
  • fs: add sync open flags 'rs' and 'rs+' (Kevin Bowman)

    +
  • +
  • windows: enable creating directory junctions with fs.symlink (Igor Zinkovsky, Bert Belder)

    +
  • +
  • windows: fix fs.lstat to properly detect symlinks. (Igor Zinkovsky)

    +
  • +
  • Fix #3270 Escape url.parse delims (isaacs)

    +
  • +
  • http: make http.get() accept a URL (Adam Malcontenti-Wilson)

    +
  • +
  • Cleanup vm module memory leakage (Marcel Laverdet)

    +
  • +
  • Optimize writing strings with Socket.write (Bert Belder)

    +
  • +
  • add support for CESU-8 and UTF-16LE encodings (koichik)

    +
  • +
  • path: add path.sep to get the path separator. (Yi, EungJun)

    +
  • +
  • net, http: add backlog parameter to .listen() (Erik Dubbelboer)

    +
  • +
  • debugger: support mirroring Date objects (Fedor Indutny)

    +
  • +
  • addon: add AtExit() function (Ben Noordhuis)

    +
  • +
  • net: signal localAddress bind failure in connect (Brian Schroeder)

    +
  • +
  • util: handle non-string return value in .inspect() (Alex Kocharin)

    +
  • +
+

Source Code: http://nodejs.org/dist/v0.7.9/node-v0.7.9.tar.gz + +

+

Windows Installer: http://nodejs.org/dist/v0.7.9/node-v0.7.9.msi + +

+

Windows x64 Files: http://nodejs.org/dist/v0.7.9/x64/ + +

+

Macintosh Installer (Universal): http://nodejs.org/dist/v0.7.9/node-v0.7.9.pkg + +

+

Other release files: http://nodejs.org/dist/v0.7.9/ + +

+

Website: http://nodejs.org/docs/v0.7.9/ + +

+

Documentation: http://nodejs.org/docs/v0.7.9/api/ +

diff --git a/doc/blog/release/v0.8.1.md b/doc/blog/release/v0.8.1.md new file mode 100644 index 00000000000..b8c84e20ddb --- /dev/null +++ b/doc/blog/release/v0.8.1.md @@ -0,0 +1,77 @@ +version: 0.8.1 +title: Version 0.8.1 (stable) +category: release +slug: node-v0-8-1-stable +date: 2012.06.29 + +2012.06.29, Version 0.8.1 (stable) + +* V8: upgrade to v3.11.10.12 + +* npm: upgrade to v1.1.33 + - Support for parallel use of the cache folder + - Retry on registry timeouts or network failures (Trent Mick) + - Reduce 'engines' failures to a warning + - Use new zsh completion if aviailable (Jeremy Cantrell) + +* Fix #3577 Un-break require('sys') + +* util: speed up formatting of large arrays/objects (Ben Noordhuis) + +* windows: make fs.realpath(Sync) work with UNC paths (Bert Belder) + +* build: fix --shared-v8 option (Ben Noordhuis) + +* doc: `detached` is a boolean (Andreas Madsen) + +* build: use proper python interpreter (Ben Noordhuis) + +* build: expand ~ in `./configure --prefix=~/a/b/c` (Ben Noordhuis) + +* build: handle CC env var with spaces (Gabriel de Perthuis) + +* build: fix V8 build when compiling with gcc 4.5 (Ben Noordhuis) + +* build: fix --shared-v8 option (Ben Noordhuis) + +* windows msi: Fix icon issue which caused huge file size (Bert Belder) + +* unix: assume that dlopen() may clobber dlerror() (Ben Noordhuis) + +* sunos: fix memory corruption bugs (Ben Noordhuis) + +* windows: better (f)utimes and (f)stat (Bert Belder) + + +Source Code: http://nodejs.org/dist/v0.8.1/node-v0.8.1.tar.gz + +Macintosh Installer (Universal): http://nodejs.org/dist/v0.8.1/node-v0.8.1.pkg + +Windows Installer: http://nodejs.org/dist/v0.8.1/node-v0.8.1-x86.msi + +Windows x64 Installer: http://nodejs.org/dist/v0.8.1/x64/node-v0.8.1-x64.msi + +Windows x64 Files: http://nodejs.org/dist/v0.8.1/x64/ + +Other release files: http://nodejs.org/dist/v0.8.1/ + +Website: http://nodejs.org/docs/v0.8.1/ + +Documentation: http://nodejs.org/docs/v0.8.1/api/ + +Shasums: + +``` +64f10cb29aaaabda83300c81d61b56a436308126 node-v0.8.1-x86.msi +75a1afca1221719ec4a9dd8ed35c0e0adbaaf153 node-v0.8.1.pkg +892790553b8121ba8624d8293d0cb7d8b01094d7 node-v0.8.1.tar.gz +85ce513182bd66c1aa3e144438022dbe4caa56a7 node.exe +592426620080c904c55ac83e151a85d42275656e node.exp +88a9177dba73597ffc08f30b886542c4d76378e2 node.lib +6b06ffd2b6e28e34189663af7b3efda5d12dd1bf node.pdb +c6d99aa58167c5489e56e2f99da99731fb4f282e x64/node-v0.8.1-x64.msi +4266ba03b2b4516d10cbc5d16eb15d5df13ebb47 x64/node.exe +7a6d0b28be88c6941aae74426199e9fb82ddfaa5 x64/node.exp +ac21ec0f61baaf584f89a92db403cd9d38ff4850 x64/node.lib +9e514c4c6c427dd4ae16edf1d2ad7a46ef9893c0 x64/node.pdb +``` diff --git a/doc/blog/release/version-0-6-11-stable.md b/doc/blog/release/version-0-6-11-stable.md new file mode 100644 index 00000000000..d57068f2750 --- /dev/null +++ b/doc/blog/release/version-0-6-11-stable.md @@ -0,0 +1,64 @@ +version: 0.6.11 +title: Version 0.6.11 (stable) +author: Isaac Schlueter +date: Fri Feb 17 2012 13:32:55 GMT-0800 (PST) +status: publish +category: release +slug: version-0-6-11-stable + +

2012.02.17 Version 0.6.11 (stable) + +

+
    +
  • http: allow multiple WebSocket RFC6455 headers (Einar Otto Stangvik)

    +
  • +
  • http: allow multiple WWW-Authenticate headers (Ben Noordhuis)

    +
  • +
  • windows: support unicode argv and environment variables (Bert Belder)

    +
  • +
  • tls: mitigate session renegotiation attacks (Ben Noordhuis)

    +
  • +
  • tcp, pipe: don't assert on uv_accept() errors (Ben Noordhuis)

    +
  • +
  • tls: Allow establishing secure connection on the existing socket (koichik)

    +
  • +
  • dgram: handle close of dgram socket before DNS lookup completes (Seth Fitzsimmons)

    +
  • +
  • windows: Support half-duplex pipes (Igor Zinkovsky)

    +
  • +
  • build: disable omit-frame-pointer on solaris systems (Dave Pacheco)

    +
  • +
  • debugger: fix --debug-brk (Ben Noordhuis)

    +
  • +
  • net: fix large file downloads failing (koichik)

    +
  • +
  • fs: fix ReadStream failure to read from existing fd (Christopher Jeffrey)

    +
  • +
  • net: destroy socket on DNS error (Stefan Rusu)

    +
  • +
  • dtrace: add missing translator (Dave Pacheco)

    +
  • +
  • unix: don't flush tty on switch to raw mode (Ben Noordhuis)

    +
  • +
  • windows: reset brightness when reverting to default text color (Bert Belder)

    +
  • +
  • npm: update to 1.1.1

    + +

    - Update which, fstream, mkdirp, request, and rimraf
    - Fix #2123 Set path properly for lifecycle scripts on windows
    - Mark the root as seen, so we don't recurse into it. Fixes #1838. (Martin Cooper)

    + +
  • +
+

Source Code: http://nodejs.org/dist/v0.6.11/node-v0.6.11.tar.gz + +

+

Windows Installer: http://nodejs.org/dist/v0.6.11/node-v0.6.11.msi + +

+

Macintosh Installer: http://nodejs.org/dist/v0.6.11/node-v0.6.11.pkg + +

+

Website: http://nodejs.org/docs/v0.6.11/ + +

+

Documentation: http://nodejs.org/docs/v0.6.11/api/ +

diff --git a/doc/blog/release/version-0-6-12-stable.md b/doc/blog/release/version-0-6-12-stable.md new file mode 100644 index 00000000000..bd20ef7da9f --- /dev/null +++ b/doc/blog/release/version-0-6-12-stable.md @@ -0,0 +1,66 @@ +version: 0.6.12 +title: Version 0.6.12 (stable) +author: Isaac Schlueter +date: Fri Mar 02 2012 13:22:49 GMT-0800 (PST) +status: publish +category: release +slug: version-0-6-12-stable + +

2012.03.02 Version 0.6.12 (stable) + +

+
    +
  • Upgrade V8 to 3.6.6.24

    +
  • +
  • dtrace ustack helper improvements (Dave Pacheco)

    +
  • +
  • API Documentation refactor (isaacs)

    +
  • +
  • #2827 net: fix race write() before and after connect() (koichik)

    +
  • +
  • #2554 #2567 throw if fs args for 'start' or 'end' are strings (AJ ONeal)

    +
  • +
  • punycode: Update to v1.0.0 (Mathias Bynens)

    +
  • +
  • Make a fat binary for the OS X pkg (isaacs)

    +
  • +
  • Fix hang on accessing process.stdin (isaacs)

    +
  • +
  • repl: make tab completion work on non-objects (Nathan Rajlich)

    +
  • +
  • Fix fs.watch on OS X (Ben Noordhuis)

    +
  • +
  • Fix #2515 nested setTimeouts cause premature process exit (Ben Noordhuis)

    +
  • +
  • windows: fix time conversion in stat (Igor Zinkovsky)

    +
  • +
  • windows: fs: handle EOF in read (Brandon Philips)

    +
  • +
  • windows: avoid IOCP short-circuit on non-ifs lsps (Igor Zinkovsky)

    +
  • +
  • Upgrade npm to 1.1.4 (isaacs)

    +

    +- windows fixes
    +- Bundle nested bundleDependencies properly
    +- install: support --save with url install targets
    +- shrinkwrap: behave properly with url-installed modules
    +- support installing uncompressed tars or single file modules from urls etc.
    +- don't run make clean on rebuild
    +- support HTTPS-over-HTTP proxy tunneling
    +

    +
  • +
+

Source Code: http://nodejs.org/dist/v0.6.12/node-v0.6.12.tar.gz + +

+

Windows Installer: http://nodejs.org/dist/v0.6.12/node-v0.6.12.msi + +

+

Macintosh Installer: http://nodejs.org/dist/v0.6.12/node-v0.6.12.pkg + +

+

Website: http://nodejs.org/docs/v0.6.12/ + +

+

Documentation: http://nodejs.org/docs/v0.6.12/api/ +

diff --git a/doc/blog/release/version-0-6-13-stable.md b/doc/blog/release/version-0-6-13-stable.md new file mode 100644 index 00000000000..2561c1df46f --- /dev/null +++ b/doc/blog/release/version-0-6-13-stable.md @@ -0,0 +1,50 @@ +version: 0.6.13 +title: Version 0.6.13 (stable) +author: Isaac Schlueter +date: Thu Mar 15 2012 10:37:02 GMT-0700 (PDT) +status: publish +category: release +slug: version-0-6-13-stable + +

2012.03.15 Version 0.6.13 (stable) + +

+
    +
  • Windows: Many libuv test fixes (Bert Belder)

    +
  • +
  • Windows: avoid uv_guess_handle crash in when fd < 0 (Bert Belder)

    +
  • +
  • Map EBUSY and ENOTEMPTY errors (Bert Belder)

    +
  • +
  • Windows: include syscall in fs errors (Bert Belder)

    +
  • +
  • Fix fs.watch ENOSYS on Linux kernel version mismatch (Ben Noordhuis)

    +
  • +
  • Update npm to 1.1.9

    +

    +- upgrade node-gyp to 0.3.5 (Nathan Rajlich)
    +- Fix isaacs/npm#2249 Add cache-max and cache-min configs
    +- Properly redirect across https/http registry requests
    +- log config usage if undefined key in set function (Kris Windham)
    +- Add support for os/cpu fields in package.json (Adam Blackburn)
    +- Automatically node-gyp packages containing a binding.gyp
    +- Fix failures unpacking in UNC shares
    +- Never create un-listable directories
    +- Handle cases where an optionalDependency fails to build +

    +
  • +
+

Source Code: http://nodejs.org/dist/v0.6.13/node-v0.6.13.tar.gz + +

+

Windows Installer: http://nodejs.org/dist/v0.6.13/node-v0.6.13.msi + +

+

Macintosh Installer: http://nodejs.org/dist/v0.6.13/node-v0.6.13.pkg + +

+

Website: http://nodejs.org/docs/v0.6.13/ + +

+

Documentation: http://nodejs.org/docs/v0.6.13/api/ +

diff --git a/doc/blog/release/version-0-6-14-stable.md b/doc/blog/release/version-0-6-14-stable.md new file mode 100644 index 00000000000..ba5183414c6 --- /dev/null +++ b/doc/blog/release/version-0-6-14-stable.md @@ -0,0 +1,55 @@ +version: 0.6.14 +title: Version 0.6.14 (stable) +author: Isaac Schlueter +date: Fri Mar 23 2012 11:22:22 GMT-0700 (PDT) +status: publish +category: release +slug: version-0-6-14-stable + +

2012.03.22 Version 0.6.14 (stable) + +

+
    +
  • net: don't crash when queued write fails (Igor Zinkovsky)

    +
  • +
  • sunos: fix EMFILE on process.memoryUsage() (Bryan Cantrill)

    +
  • +
  • crypto: fix compile-time error with openssl 0.9.7e (Ben Noordhuis)

    +
  • +
  • unix: ignore ECONNABORTED errors from accept() (Ben Noordhuis)

    +
  • +
  • Add UV_ENOSPC and mappings to it (Bert Belder)

    +
  • +
  • http-parser: Fix response body is not read (koichik)

    +
  • +
  • Upgrade npm to 1.1.12

    +

    +- upgrade node-gyp to 0.3.7
    +- work around AV-locked directories on Windows
    +- Fix isaacs/npm#2293 Don't try to 'uninstall' /
    +- Exclude symbolic links from packages.
    +- Fix isaacs/npm#2275 Spurious 'unresolvable cycle' error.
    +- Exclude/include dot files as if they were normal files +

    +
  • +
+

Source Code: http://nodejs.org/dist/v0.6.14/node-v0.6.14.tar.gz + +

+

Windows Installer: http://nodejs.org/dist/v0.6.14/node-v0.6.14.msi + +

+

Windows x64 Files: http://nodejs.org/dist/v0.6.14/x64/ + +

+

Macintosh Installer (Universal): http://nodejs.org/dist/v0.6.14/node-v0.6.14.pkg + +

+

Other release files: http://nodejs.org/dist/v0.6.14/ + +

+

Website: http://nodejs.org/docs/v0.6.14/ + +

+

Documentation: http://nodejs.org/docs/v0.6.14/api/ +

diff --git a/doc/blog/release/version-0-6-15-stable.md b/doc/blog/release/version-0-6-15-stable.md new file mode 100644 index 00000000000..e6f0502f74b --- /dev/null +++ b/doc/blog/release/version-0-6-15-stable.md @@ -0,0 +1,53 @@ +version: 0.6.15 +title: Version 0.6.15 (stable) +author: Isaac Schlueter +date: Mon Apr 09 2012 10:39:18 GMT-0700 (PDT) +status: publish +category: release +slug: version-0-6-15-stable + +

2012.04.09 Version 0.6.15 (stable) + +

+
    +
  • Update npm to 1.1.16

    +
  • +
  • Show licenses in binary installers.

    +
  • +
  • unix: add uv_fs_read64, uv_fs_write64 and uv_fs_ftruncate64 (Ben Noordhuis)

    +
  • +
  • add 64bit offset fs functions (Igor Zinkovsky)

    +
  • +
  • windows: don't report ENOTSOCK when attempting to bind an udp handle twice (Bert Belder)

    +
  • +
  • windows: backport pipe-connect-to-file fixes from master (Bert Belder)

    +
  • +
  • windows: never call fs event callbacks after closing the watcher (Bert Belder)

    +
  • +
  • fs.readFile: don't make the callback before the fd is closed (Bert Belder)

    +
  • +
  • windows: use 64bit offsets for uv_fs apis (Igor Zinkovsky)

    +
  • +
  • Fix #2061: segmentation fault on OS X due to stat size mismatch (Ben Noordhuis)

    +
  • +
+

Source Code: http://nodejs.org/dist/v0.6.15/node-v0.6.15.tar.gz + +

+

Windows Installer: http://nodejs.org/dist/v0.6.15/node-v0.6.15.msi + +

+

Windows x64 Files: http://nodejs.org/dist/v0.6.15/x64/ + +

+

Macintosh Installer (Universal): http://nodejs.org/dist/v0.6.15/node-v0.6.15.pkg + +

+

Other release files: http://nodejs.org/dist/v0.6.15/ + +

+

Website: http://nodejs.org/docs/v0.6.15/ + +

+

Documentation: http://nodejs.org/docs/v0.6.15/api/ +

diff --git a/doc/blog/release/version-0-6-16-stable.md b/doc/blog/release/version-0-6-16-stable.md new file mode 100644 index 00000000000..69f8b31700f --- /dev/null +++ b/doc/blog/release/version-0-6-16-stable.md @@ -0,0 +1,59 @@ +version: 0.6.16 +title: Version 0.6.16 (stable) +author: Isaac Schlueter +date: Mon Apr 30 2012 11:13:50 GMT-0700 (PDT) +status: publish +category: release +slug: version-0-6-16-stable + +

2012.04.30 Version 0.6.16 (stable) + +

+
    +
  • Upgrade V8 to 3.6.6.25

    +
  • +
  • Upgrade npm to 1.1.18

    +
  • +
  • Windows: add mappings for UV_ENOENT (Bert Belder)

    +
  • +
  • linux: add IN_MOVE_SELF to inotify event mask (Ben Noordhuis)

    +
  • +
  • unix: call pipe handle connection cb on accept() error (Ben Noordhuis)

    +
  • +
  • unix: handle EWOULDBLOCK (Ben Noordhuis)

    +
  • +
  • map EWOULDBLOCK to UV_EAGAIN (Ben Noordhuis)

    +
  • +
  • Map ENOMEM to UV_ENOMEM (isaacs)

    +
  • +
  • Child process: support the gid and uid options (Bert Belder)

    +
  • +
  • test: cluster: add worker death event test (Ben Noordhuis)

    +
  • +
  • typo in node_http_parser (isaacs)

    +
  • +
  • http_parser: Eat CRLF between requests, even on connection:close. (Ben Noordhuis)

    +
  • +
  • don't check return value of unsetenv (Ben Noordhuis)

    +
  • +
+

Source Code: http://nodejs.org/dist/v0.6.16/node-v0.6.16.tar.gz + +

+

Windows Installer: http://nodejs.org/dist/v0.6.16/node-v0.6.16.msi + +

+

Windows x64 Files: http://nodejs.org/dist/v0.6.16/x64/ + +

+

Macintosh Installer (Universal): http://nodejs.org/dist/v0.6.16/node-v0.6.16.pkg + +

+

Other release files: http://nodejs.org/dist/v0.6.16/ + +

+

Website: http://nodejs.org/docs/v0.6.16/ + +

+

Documentation: http://nodejs.org/docs/v0.6.16/api/ +

diff --git a/doc/blog/release/version-0-6-17-stable.md b/doc/blog/release/version-0-6-17-stable.md new file mode 100644 index 00000000000..3512e1df2f2 --- /dev/null +++ b/doc/blog/release/version-0-6-17-stable.md @@ -0,0 +1,47 @@ +version: 0.6.17 +title: Version 0.6.17 (stable) +author: Isaac Schlueter +date: Fri May 04 2012 13:33:12 GMT-0700 (PDT) +status: publish +category: release +slug: version-0-6-17-stable + +

2012.05.04 Version 0.6.17 (stable) + +

+
    +
  • Upgrade npm to 1.1.21

    +
  • +
  • uv: Add support for EROFS errors (Ben Noordhuis, Maciej Małecki)

    +
  • +
  • uv: Add support for EIO and ENOSPC errors (Fedor Indutny)

    +
  • +
  • windows: Add support for EXDEV errors (Bert Belder)

    +
  • +
  • http: Fix client memory leaks (isaacs, Vincent Voyer)

    +
  • +
  • fs: fix file descriptor leak in sync functions (Ben Noordhuis)

    +
  • +
  • fs: fix ReadStream / WriteStream double close bug (Ben Noordhuis)

    +
  • +
+

Source Code: http://nodejs.org/dist/v0.6.17/node-v0.6.17.tar.gz + +

+

Windows Installer: http://nodejs.org/dist/v0.6.17/node-v0.6.17.msi + +

+

Windows x64 Files: http://nodejs.org/dist/v0.6.17/x64/ + +

+

Macintosh Installer (Universal): http://nodejs.org/dist/v0.6.17/node-v0.6.17.pkg + +

+

Other release files: http://nodejs.org/dist/v0.6.17/ + +

+

Website: http://nodejs.org/docs/v0.6.17/ + +

+

Documentation: http://nodejs.org/docs/v0.6.17/api/ +

diff --git a/doc/blog/release/version-0-6-18-stable.md b/doc/blog/release/version-0-6-18-stable.md new file mode 100644 index 00000000000..0cf179bfce7 --- /dev/null +++ b/doc/blog/release/version-0-6-18-stable.md @@ -0,0 +1,59 @@ +version: 0.6.18 +title: Version 0.6.18 (stable) +author: Isaac Schlueter +date: Tue May 15 2012 10:06:13 GMT-0700 (PDT) +status: publish +category: release +slug: version-0-6-18-stable + +

2012.05.15 Version 0.6.18 (stable) + +

+
    +
  • windows: skip GetFileAttributes call when opening a file (Bert Belder)

    +
  • +
  • crypto: add PKCS12/PFX support (Sambasiva Suda)

    +
  • +
  • #3240: child_process: delete NODE_CHANNEL_FD from env in spawn (Ben Noordhuis)

    +
  • +
  • windows: add test for path.normalize with UNC paths (Bert Belder)

    +
  • +
  • windows: make path.normalize convert all slashes to backslashes (Bert Belder)

    +
  • +
  • fs: Automatically close FSWatcher on error (Bert Belder)

    +
  • +
  • #3258: fs.ReadStream.pause() emits duplicate data event (koichik)

    +
  • +
  • pipe_wrap: don't assert() on pipe accept errors (Ben Noordhuis)

    +
  • +
  • Better exception output for module load and process.nextTick (Felix Geisendörfer)

    +
  • +
  • zlib: fix error reporting (Ben Noordhuis)

    +
  • +
  • http: Don't destroy on timeout (isaacs)

    +
  • +
  • #3231: http: Don't try to emit error on a null'ed req object (isaacs)

    +
  • +
  • #3236: http: Refactor ClientRequest.onSocket (isaacs)

    +
  • +
+

Source Code: http://nodejs.org/dist/v0.6.18/node-v0.6.18.tar.gz + +

+

Windows Installer: http://nodejs.org/dist/v0.6.18/node-v0.6.18.msi + +

+

Windows x64 Files: http://nodejs.org/dist/v0.6.18/x64/ + +

+

Macintosh Installer (Universal): http://nodejs.org/dist/v0.6.18/node-v0.6.18.pkg + +

+

Other release files: http://nodejs.org/dist/v0.6.18/ + +

+

Website: http://nodejs.org/docs/v0.6.18/ + +

+

Documentation: http://nodejs.org/docs/v0.6.18/api/ +

diff --git a/doc/blog/release/version-0-7-10-unstable.md b/doc/blog/release/version-0-7-10-unstable.md new file mode 100644 index 00000000000..3e149111478 --- /dev/null +++ b/doc/blog/release/version-0-7-10-unstable.md @@ -0,0 +1,86 @@ +version: 0.7.10 +title: Version 0.7.10 (unstable) +author: Isaac Schlueter +date: Mon Jun 11 2012 09:00:25 GMT-0700 (PDT) +status: publish +category: release +slug: version-0-7-10-unstable + +

2012.06.11, Version 0.7.10 (unstable) + +

+

This is the second-to-last release on the 0.7 branch. Version 0.8.0 +will be released some time next week. As other even-numbered Node +releases before it, the v0.8.x releases will maintain API and binary +compatibility. + +

+

The major changes are detailed in +https://github.com/joyent/node/wiki/API-changes-between-v0.6-and-v0.8 + +

+

Please try out this release. There will be very few changes between +this and the v0.8.x release family. This is the last chance to comment +on the API before it is locked down for stability. + + +

+
    +
  • Roll V8 back to 3.9.24.31

    +
  • +
  • build: x64 target should always pass -m64 (Robert Mustacchi)

    +
  • +
  • add NODE_EXTERN to node::Start (Joel Brandt)

    +
  • +
  • repl: Warn about running npm commands (isaacs)

    +
  • +
  • slab_allocator: fix crash in dtor if V8 is dead (Ben Noordhuis)

    +
  • +
  • slab_allocator: fix leak of Persistent handles (Shigeki Ohtsu)

    +
  • +
  • windows/msi: add node.js prompt to startmenu (Jeroen Janssen)

    +
  • +
  • windows/msi: fix adding node to PATH (Jeroen Janssen)

    +
  • +
  • windows/msi: add start menu links when installing (Jeroen Janssen)

    +
  • +
  • windows: don't install x64 version into the 'program files (x86)' folder (Matt Gollob)

    +
  • +
  • domain: Fix #3379 domain.intercept no longer passes error arg to cb (Marc Harter)

    +
  • +
  • fs: make callbacks run in global context (Ben Noordhuis)

    +
  • +
  • fs: enable fs.realpath on windows (isaacs)

    +
  • +
  • child_process: expose UV_PROCESS_DETACHED as options.detached (Charlie McConnell)

    +
  • +
  • child_process: new stdio API for .spawn() method (Fedor Indutny)

    +
  • +
  • child_process: spawn().ref() and spawn().unref() (Fedor Indutny)

    +
  • +
  • Upgrade npm to 1.1.25

    +
  • +
    • Enable npm link on windows
    • +
    • Properly remove sh-shim on Windows
    • +
    • Abstract out registry client and logger
    +
+

Source Code: http://nodejs.org/dist/v0.7.10/node-v0.7.10.tar.gz + +

+

Windows Installer: http://nodejs.org/dist/v0.7.10/node-v0.7.10.msi + +

+

Windows x64 Files: http://nodejs.org/dist/v0.7.10/x64/ + +

+

Macintosh Installer (Universal): http://nodejs.org/dist/v0.7.10/node-v0.7.10.pkg + +

+

Other release files: http://nodejs.org/dist/v0.7.10/ + +

+

Website: http://nodejs.org/docs/v0.7.10/ + +

+

Documentation: http://nodejs.org/docs/v0.7.10/api/ +

diff --git a/doc/blog/release/version-0-7-11-unstable.md b/doc/blog/release/version-0-7-11-unstable.md new file mode 100644 index 00000000000..e8fd71a4e19 --- /dev/null +++ b/doc/blog/release/version-0-7-11-unstable.md @@ -0,0 +1,80 @@ +version: 0.7.11 +title: Version 0.7.11 (unstable) +author: Isaac Schlueter +date: Fri Jun 15 2012 12:45:20 GMT-0700 (PDT) +status: publish +category: release +slug: version-0-7-11-unstable + +

This is the most stable 0.7 release yet. Please try it out. + +

+

Version 0.8 will be out very soon. You can follow the remaining issues +on the github issue tracker. + +

+

https://github.com/joyent/node/issues?milestone=10&state=open + +

+

2012.06.15, Version 0.7.11 (unstable) + +

+
    +
  • V8: Upgrade to v3.11.10

    +
  • +
  • npm: Upgrade to 1.1.26

    +
  • +
  • doc: Improve cross-linking in API docs markdown (Ben Kelly)

    +
  • +
  • Fix #3425: removeAllListeners should delete array (Reid Burke)

    +
  • +
  • cluster: don't silently drop messages when the write queue gets big (Bert Belder)

    +
  • +
  • Add Buffer.concat method (isaacs)

    +
  • +
  • windows: make symlinks tolerant to forward slashes (Bert Belder)

    +
  • +
  • build: Add node.d and node.1 to installer (isaacs)

    +
  • +
  • cluster: rename worker.unqiueID to worker.id (Andreas Madsen)

    +
  • +
  • Windows: Enable ETW events on Windows for existing DTrace probes. (Igor Zinkovsky)

    +
  • +
  • test: bundle node-weak in test/gc so that it doesn't need to be downloaded (Nathan Rajlich)

    +
  • +
  • Make many tests pass on Windows (Bert Belder)

    +
  • +
  • Fix #3388 Support listening on file descriptors (isaacs)

    +
  • +
  • Fix #3407 Add os.tmpDir() (isaacs)

    +
  • +
  • Unbreak the snapshotted build on Windows (Bert Belder)

    +
  • +
  • Clean up child_process.kill throws (Bert Belder)

    +
  • +
  • crypto: make cipher/decipher accept buffer args (Ben Noordhuis)

    +
  • +
+

Source Code: http://nodejs.org/dist/v0.7.11/node-v0.7.11.tar.gz + +

+

Macintosh Installer (Universal): http://nodejs.org/dist/v0.7.11/node-v0.7.11.pkg + +

+

Windows Installer: http://nodejs.org/dist/v0.7.11/node-v0.7.11-x86.msi + +

+

Windows x64 Installer: http://nodejs.org/dist/v0.7.11/node-v0.7.11-x64.msi + +

+

Windows x64 Files: http://nodejs.org/dist/v0.7.11/x64/ + +

+

Other release files: http://nodejs.org/dist/v0.7.11/ + +

+

Website: http://nodejs.org/docs/v0.7.11/ + +

+

Documentation: http://nodejs.org/docs/v0.7.11/api/ +

diff --git a/doc/blog/release/version-0-7-12.md b/doc/blog/release/version-0-7-12.md new file mode 100644 index 00000000000..91e571d2e39 --- /dev/null +++ b/doc/blog/release/version-0-7-12.md @@ -0,0 +1,56 @@ +version: 0.7.12 +title: Version 0.7.12 +author: Isaac Schlueter +date: Tue Jun 19 2012 16:31:09 GMT-0700 (PDT) +status: publish +category: release +slug: version-0-7-12 + +

2012.06.19, Version 0.7.12 (unstable)

+

This is the last release on the 0.7 branch. Version 0.8.0 will be released some time later this week, barring any major problems.

+

As with other even-numbered Node releases before it, the v0.8.x releases will maintain API and binary compatibility.

+

The major changes between v0.6 and v0.8 are detailed in https://github.com/joyent/node/wiki/API-changes-between-v0.6-and-v0.8

+

Please try out this release. There will be very virtually no changes between this and the v0.8.x release family. This is the last chance to comment before it is locked down for stability. The API is effectively frozen now.

+

This version adds backwards-compatible shims for binary addons that use libeio and libev directly. If you find that binary modules that could compile on v0.6 can not compile on this version, please let us know. Note that libev is officially deprecated in v0.8, and will be removed in v0.9. You should be porting your modules to use libuv as soon as possible.

+

V8 is on 3.11.10 currently, and will remain on the V8 3.11.x branch for the duration of Node v0.8.x.

+
  • npm: Upgrade to 1.1.30
    - Improved 'npm init'
    - Fix the 'cb never called' error from 'oudated' and 'update'
    - Add --save-bundle|-B config
    - Fix isaacs/npm#2465: Make npm script and windows shims cygwin-aware
    - Fix isaacs/npm#2452 Use --save(-dev|-optional) in npm rm
    - logstream option to replace removed logfd (Rod Vagg)
    - Read default descriptions from README.md files

    +
  • Shims to support deprecated ev_* and eio_* methods (Ben Noordhuis)

    +
  • #3118 net.Socket: Delay pause/resume until after connect (isaacs)

    +
  • #3465 Add ./configure --no-ifaddrs flag (isaacs)

    +
  • child_process: add .stdin stream to forks (Fedor Indutny)

    +
  • build: fix make install DESTDIR=/path (Ben Noordhuis)

    +
  • tls: fix off-by-one error in renegotiation check (Ben Noordhuis)

    +
  • crypto: Fix diffie-hellman key generation UTF-8 errors (Fedor Indutny)

    +
  • node: change the constructor name of process from EventEmitter to process (Andreas Madsen)

    +
  • net: Prevent property access throws during close (Reid Burke)

    +
  • querystring: improved speed and code cleanup (Felix Böhm)

    +
  • sunos: fix assertion errors breaking fs.watch() (Fedor Indutny)

    +
  • unix: stat: detect sub-second changes (Ben Noordhuis)

    +
  • add stat() based file watcher (Ben Noordhuis)

    +

Source Code: http://nodejs.org/dist/v0.7.12/node-v0.7.12.tar.gz

+

Macintosh Installer (Universal): http://nodejs.org/dist/v0.7.12/node-v0.7.12.pkg

+

Windows Installer: http://nodejs.org/dist/v0.7.12/node-v0.7.12-x86.msi

+

Windows x64 Installer: http://nodejs.org/dist/v0.7.12/x64/node-v0.7.12-x64.msi

+

Windows x64 Files: http://nodejs.org/dist/v0.7.12/x64/

+

Other release files: http://nodejs.org/dist/v0.7.12/

+

Website: http://nodejs.org/docs/v0.7.12/

+

Documentation: http://nodejs.org/docs/v0.7.12/api/

+ +

Shasums

+ +
ded6a2197b1149b594eb45fea921e8538ba442aa  blog.html
+dfabff0923d4b4f1d53bd9831514c1ac8c4b1876  email.md
+be313d35511e6d7e43cae5fa2b18f3e0d2275ba1  node-v0.7.12-x86.msi
+8f7ba0c8283e3863de32fd5c034f5b599c78f830  node-v0.7.12.pkg
+cb570abacbf4eb7e23c3d2620d00dd3080d9c19d  node-v0.7.12.tar.gz
+e13a6edfcba1c67ffe794982dd20a222ce8ce40f  node.exe
+20906ad76a43eca52795b2a089654a105e11c1e6  node.exp
+acbcbb87b6f7f2af34a3ed0abe6131d9e7a237af  node.lib
+4013d5b25fe36ae4245433b972818686cd9a2205  node.pdb
+6c0a7a2e8ee360e2800156293fb2f6a5c1a57382  npm-1.1.30.tgz
+9d23e42e8260fa20001d5618d2583a62792bf63f  npm-1.1.30.zip
+840157b2d6f7389ba70b07fc9ddc048b92c501cc  x64/node-v0.7.12-x64.msi
+862d42706c21ea83bf73cd827101f0fe598b0cf7  x64/node.exe
+de0af95fac083762f99c875f91bab830dc030f71  x64/node.exp
+3122bd886dfb96f3b41846cef0bdd7e97326044a  x64/node.lib
+e0fa4e42cd19cadf8179e492ca606b7232bbc018  x64/node.pdb
diff --git a/doc/blog/release/version-0-7-4-unstable.md b/doc/blog/release/version-0-7-4-unstable.md new file mode 100644 index 00000000000..01bc92ae55e --- /dev/null +++ b/doc/blog/release/version-0-7-4-unstable.md @@ -0,0 +1,50 @@ +version: 0.7.4 +title: Node v0.7.4 (unstable) +author: Isaac Schlueter +date: Wed Feb 15 2012 11:38:35 GMT-0800 (PST) +status: publish +category: release +slug: version-0-7-4-unstable + +

2012.02.14, Version 0.7.4 (unstable) + +

+
    +
  • Upgrade V8 to 3.9.5

    +
  • +
  • Upgrade npm to 1.1.1

    +
  • +
  • build: Detect host_arch better (Karl Skomski)

    +
  • +
  • debugger: export debug_port to process (Fedor Indutny)

    +
  • +
  • api docs: CSS bug fixes (isaacs)

    +
  • +
  • build: use -fPIC for native addons on UNIX (Nathan Rajlich)

    +
  • +
  • Re-add top-level v8::Locker (Marcel Laverdet)

    +
  • +
  • Move images out of the dist tarballs (isaacs)

    +
  • +
  • libuv: Remove uv_export and uv_import (Ben Noordhuis)

    +
  • +
  • build: Support x64 build on Windows (Igor Zinkovsky)

    +
  • +
+

Source Code: http://nodejs.org/dist/v0.7.4/node-v0.7.4.tar.gz + +

+

Windows Installer: http://nodejs.org/dist/v0.7.4/node-v0.7.4.msi + +

+

Macintosh Installer: http://nodejs.org/dist/v0.7.4/node-v0.7.4.pkg + +

+

Other release files: http://nodejs.org/dist/v0.7.4/ + +

+

Website: http://nodejs.org/docs/v0.7.4/ + +

+

Documentation: http://nodejs.org/docs/v0.7.4/api/ +

diff --git a/doc/blog/release/version-0-7-5-unstable.md b/doc/blog/release/version-0-7-5-unstable.md new file mode 100644 index 00000000000..bc1e6047dd3 --- /dev/null +++ b/doc/blog/release/version-0-7-5-unstable.md @@ -0,0 +1,62 @@ +version: 0.7.5 +title: Version 0.7.5 (unstable) +author: Isaac Schlueter +date: Thu Feb 23 2012 14:45:21 GMT-0800 (PST) +status: publish +category: release +slug: version-0-7-5-unstable + +

2012.02.23, Version 0.7.5 (unstable) + +

+
    +
  • startup speed improvements (Maciej Małecki)

    +
  • +
  • crypto: add function getDiffieHellman() (Tomasz Buchert)

    +
  • +
  • buffer: support decoding of URL-safe base64 (Ben Noordhuis)

    +
  • +
  • Make QueryString.parse() even faster (Brian White)

    +
  • +
  • url: decode url entities in auth section (Ben Noordhuis)

    +
  • +
  • http: support PURGE request method (Ben Noordhuis)

    +
  • +
  • http: Generate Date headers on responses (Mark Nottingham)

    +
  • +
  • Fix #2762: Add callback to close function. (Mikeal Rogers)

    +
  • +
  • dgram: fix out-of-bound memory read (Ben Noordhuis)

    +
  • +
  • repl: add automatic loading of built-in libs (Brandon Benvie)

    +
  • +
  • repl: remove double calls where possible (Fedor Indutny)

    +
  • +
  • Readline improvements. Related: #2737 #2756 (Colton Baker)

    +
  • +
  • build: disable -fomit-frame-pointer on solaris (Dave Pacheco)

    +
  • +
  • build: arch detection improvements (Nathan Rajlich)

    +
  • +
  • build: Make a fat binary for the OS X make pkg. (Nathan Rajlich)

    +
  • +
  • jslint src/ and lib/ on 'make test' (isaacs)

    +
  • +
+

Source Code: http://nodejs.org/dist/v0.7.5/node-v0.7.5.tar.gz + +

+

Windows Installer: http://nodejs.org/dist/v0.7.5/node-v0.7.5.msi + +

+

Macintosh Installer: http://nodejs.org/dist/v0.7.5/node-v0.7.5.pkg + +

+

Other release files: http://nodejs.org/dist/v0.7.5/ + +

+

Website: http://nodejs.org/docs/v0.7.5/ + +

+

Documentation: http://nodejs.org/docs/v0.7.5/api/ +

diff --git a/doc/blog/release/version-0-7-6-unstable.md b/doc/blog/release/version-0-7-6-unstable.md new file mode 100644 index 00000000000..ecf67f3ea06 --- /dev/null +++ b/doc/blog/release/version-0-7-6-unstable.md @@ -0,0 +1,72 @@ +version: 0.7.6 +title: Version 0.7.6 (unstable) +author: Isaac Schlueter +date: Tue Mar 13 2012 14:12:30 GMT-0700 (PDT) +status: publish +category: release +slug: version-0-7-6-unstable + +

2012.03.13, Version 0.7.6 (unstable) + +

+
    +
  • Upgrade v8 to 3.9.17

    +
  • +
  • Upgrade npm to 1.1.8

    +

    +- Add support for os/cpu fields in package.json (Adam Blackburn)
    +- Automatically node-gyp packages containing a binding.gyp
    +- Fix failures unpacking in UNC shares
    +- Never create un-listable directories
    +- Handle cases where an optionalDependency fails to build
    +

    +
  • +
  • events: newListener emit correct fn when using 'once' (Roly Fentanes)

    +
  • +
  • url: Ignore empty port component (Łukasz Walukiewicz)

    +
  • +
  • module: replace 'children' array (isaacs)

    +
  • +
  • tls: parse multiple values of a key in ssl certificate (Sambasiva Suda)

    +
  • +
  • cluster: support passing of named pipes (Ben Noordhuis)

    +
  • +
  • Windows: include syscall in fs errors (Bert Belder)

    +
  • +
  • http: #2888 Emit end event only once (Igor Zinkovsky)

    +
  • +
  • readline: add multiline support (Rlidwka)

    +
  • +
  • process: add process.hrtime() (Nathan Rajlich)

    +
  • +
  • net, http, https: add localAddress option (Dmitry Nizovtsev)

    +
  • +
  • addon improvements (Nathan Rajlich)

    +
  • +
  • build improvements (Ben Noordhuis, Sadique Ali, T.C. Hollingsworth, Nathan Rajlich)

    +
  • +
  • add support for "SEARCH" request methods (Nathan Rajlich)

    +
  • +
  • expose the zlib and http_parser version in process.versions (Nathan Rajlich)

    +
  • +
+

Source Code: http://nodejs.org/dist/v0.7.6/node-v0.7.6.tar.gz + +

+

Windows Installer: http://nodejs.org/dist/v0.7.6/node-v0.7.6.msi + +

+

Windows x64 Files: http://nodejs.org/dist/v0.7.6/x64/ + +

+

Macintosh Installer (Universal): http://nodejs.org/dist/v0.7.6/node-v0.7.6.pkg + +

+

Other release files: http://nodejs.org/dist/v0.7.6/ + +

+

Website: http://nodejs.org/docs/v0.7.6/ + +

+

Documentation: http://nodejs.org/docs/v0.7.6/api/ +

diff --git a/doc/blog/release/version-0-7-7-unstable.md b/doc/blog/release/version-0-7-7-unstable.md new file mode 100644 index 00000000000..6cdcc231285 --- /dev/null +++ b/doc/blog/release/version-0-7-7-unstable.md @@ -0,0 +1,71 @@ +version: 0.7.7 +title: Version 0.7.7 (unstable) +author: Isaac Schlueter +date: Fri Mar 30 2012 11:56:19 GMT-0700 (PDT) +status: publish +category: release +slug: version-0-7-7-unstable + +

2012.03.30, Version 0.7.7 (unstable) + +

+
    +
  • Upgrade V8 to 3.9.24.7

    +
  • +
  • Upgrade npm to 1.1.15

    +
  • +
  • Handle Emoji characters properly (Erik Corry, Bert Belder)

    +
  • +
  • readline: migrate ansi/vt100 logic from tty to readline (Nathan Rajlich)

    +
  • +
  • readline: Fix multiline handling (Alex Kocharin)

    +
  • +
  • add a -i/--interactive flag to force the REPL (Nathan Rajlich)

    +
  • +
  • debugger: add breakOnException command (Fedor Indutny)

    +
  • +
  • cluster: kill workers when master dies (Andreas Madsen)

    +
  • +
  • cluster: add graceful disconnect support (Andreas Madsen)

    +
  • +
  • child_process: Separate 'close' event from 'exit' (Charlie McConnell)

    +
  • +
  • typed arrays: add Uint8ClampedArray (Mikael Bourges-Sevenier)

    +
  • +
  • buffer: Fix byte alignment issues (Ben Noordhuis, Erik Lundin)

    +
  • +
  • tls: fix CryptoStream.setKeepAlive() (Shigeki Ohtsu)

    +
  • +
  • Expose http parse error codes (Felix Geisendörfer)

    +
  • +
  • events: don't delete the listeners array (Ben Noordhuis, Nathan Rajlich)

    +
  • +
  • process: add process.config to view node's ./configure settings (Nathan Rajlich)

    +
  • +
  • process: process.execArgv to see node's arguments (Micheil Smith)

    +
  • +
  • process: fix process.title setter (Ben Noordhuis)

    +
  • +
  • timers: handle negative or non-numeric timeout values (Ben Noordhuis)

    +
  • +
+

Source Code: http://nodejs.org/dist/v0.7.7/node-v0.7.7.tar.gz + +

+

Windows Installer: http://nodejs.org/dist/v0.7.7/node-v0.7.7.msi + +

+

Windows x64 Files: http://nodejs.org/dist/v0.7.7/x64/ + +

+

Macintosh Installer (Universal): http://nodejs.org/dist/v0.7.7/node-v0.7.7.pkg + +

+

Other release files: http://nodejs.org/dist/v0.7.7/ + +

+

Website: http://nodejs.org/docs/v0.7.7/ + +

+

Documentation: http://nodejs.org/docs/v0.7.7/api/ +

diff --git a/doc/blog/release/version-0-7-8-unstable.md b/doc/blog/release/version-0-7-8-unstable.md new file mode 100644 index 00000000000..8e87a9007d4 --- /dev/null +++ b/doc/blog/release/version-0-7-8-unstable.md @@ -0,0 +1,71 @@ +version: 0.7.8 +title: Version 0.7.8 (unstable) +author: Isaac Schlueter +date: Wed Apr 18 2012 10:39:02 GMT-0700 (PDT) +status: publish +category: release +slug: version-0-7-8-unstable + +

2012.04.18, Version 0.7.8, (unstable) + +

+
    +
  • Upgrade V8 to 3.9.24.9

    +
  • +
  • Upgrade OpenSSL to 1.0.0f

    +
  • +
  • Upgrade npm to 1.1.18

    +
  • +
  • Show licenses in Binary installers

    +
  • +
  • Domains (isaacs)

    +
  • +
  • readline: rename "end" to "close" (Nathan Rajlich)

    +
  • +
  • tcp: make getsockname() return address family as string (Shigeki Ohtsu)

    +
  • +
  • http, https: fix .setTimeout() (ssuda)

    +
  • +
  • os: add cross platform EOL character (Mustansir Golawala)

    +
  • +
  • typed arrays: unexport SizeOfArrayElementForType() (Aaron Jacobs)

    +
  • +
  • net: honor 'enable' flag in .setNoDelay() (Ben Noordhuis)

    +
  • +
  • child_process: emit error when .kill fails (Andreas Madsen)

    +
  • +
  • gyp: fix 'argument list too long' build error (Ben Noordhuis)

    +
  • +
  • fs.WriteStream: Handle modifications to fs.open (isaacs)

    +
  • +
  • repl, readline: Handle newlines better (Nathan Rajlich, Nathan Friedly)

    +
  • +
  • build: target OSX 10.5 when building on darwin (Nathan Rajlich)

    +
  • +
  • Fix #3052 Handle errors properly in zlib (isaacs)

    +
  • +
  • build: add support for DTrace and postmortem (Dave Pacheco)

    +
  • +
  • core: add reusable Slab allocator (Ben Noordhuis)

    +
  • +
+

Source Code: http://nodejs.org/dist/v0.7.8/node-v0.7.8.tar.gz + +

+

Windows Installer: http://nodejs.org/dist/v0.7.8/node-v0.7.8.msi + +

+

Windows x64 Files: http://nodejs.org/dist/v0.7.8/x64/ + +

+

Macintosh Installer (Universal): http://nodejs.org/dist/v0.7.8/node-v0.7.8.pkg + +

+

Other release files: http://nodejs.org/dist/v0.7.8/ + +

+

Website: http://nodejs.org/docs/v0.7.8/ + +

+

Documentation: http://nodejs.org/docs/v0.7.8/api/ +

diff --git a/doc/blog/video/bryan-cantrill-instrumenting-the-real-time-web.md b/doc/blog/video/bryan-cantrill-instrumenting-the-real-time-web.md new file mode 100644 index 00000000000..0c26cb7a493 --- /dev/null +++ b/doc/blog/video/bryan-cantrill-instrumenting-the-real-time-web.md @@ -0,0 +1,42 @@ +title: Bryan Cantrill: Instrumenting the Real Time Web +author: Isaac Schlueter +date: Tue May 08 2012 10:00:34 GMT-0700 (PDT) +status: publish +category: video +slug: bryan-cantrill-instrumenting-the-real-time-web + +Bryan Cantrill, VP of Engineering at Joyent, describes the challenges of instrumenting a distributed, dynamic, highly virtualized system -- and what their experiences taught them about the problem, the technologies used to tackle it, and promising approaches. + +This talk was given at Velocity Conf in 2011. + +
+ + +
+ Instrumenting the real-time web + + + + + + + + +
+ View more presentations from bcantrill +
+
+
diff --git a/doc/blog/video/welcome-to-the-node-blog.md b/doc/blog/video/welcome-to-the-node-blog.md new file mode 100644 index 00000000000..3ac39858326 --- /dev/null +++ b/doc/blog/video/welcome-to-the-node-blog.md @@ -0,0 +1,13 @@ +title: Welcome to the Node blog +author: ryandahl +date: Thu Mar 17 2011 20:17:12 GMT-0700 (PDT) +status: publish +category: video +slug: welcome-to-the-node-blog + +Since Livejournal is disintegrating into Russian spam, I'm moving my technical blog to http://blog.nodejs.org/. I hope to do frequent small posts about what's going on in Node development and include posts from other core Node developers. Please subscribe to the RSS feed. + +To avoid making this post completely devoid of content, here is a new video from a talk I gave at the SF PHP group tastefully produced by Marakana: + diff --git a/doc/blog/vulnerability/http-server-security-vulnerability-please-upgrade-to-0-6-17.md b/doc/blog/vulnerability/http-server-security-vulnerability-please-upgrade-to-0-6-17.md new file mode 100644 index 00000000000..22a8c71922d --- /dev/null +++ b/doc/blog/vulnerability/http-server-security-vulnerability-please-upgrade-to-0-6-17.md @@ -0,0 +1,45 @@ +title: HTTP Server Security Vulnerability: Please upgrade to 0.6.17 +author: Isaac Schlueter +date: Mon May 07 2012 10:02:01 GMT-0700 (PDT) +status: publish +category: vulnerability +slug: http-server-security-vulnerability-please-upgrade-to-0-6-17 + +

tl;dr

+ +
  • A carefully crafted attack request can cause the contents of the HTTP parser's buffer to be appended to the attacking request's header, making it appear to come from the attacker. Since it is generally safe to echo back contents of a request, this can allow an attacker to get an otherwise correctly designed server to divulge information about other requests. It is theoretically possible that it could enable header-spoofing attacks, though such an attack has not been demonstrated.

  • +
  • Versions affected: All versions of the 0.5/0.6 branch prior to 0.6.17, and all versions of the 0.7 branch prior to 0.7.8. Versions in the 0.4 branch are not affected.
  • +
  • Fix: Upgrade to v0.6.17, or apply the fix in c9a231d to your system.
+ +

Details

+ +

A few weeks ago, Matthew Daley found a security vulnerability in Node's HTTP implementation, and thankfully did the responsible thing and reported it to us via email. He explained it quite well, so I'll quote him here:

+
+

There is a vulnerability in node's `http_parser` binding which allows information disclosure to a remote attacker: + +

+

In node::StringPtr::Update, an attempt is made at an optimization on certain inputs (`node_http_parser.cc`, line 151). The intent is that if the current string pointer plus the current string size is equal to the incoming string pointer, the current string size is just increased to match, as the incoming string lies just beyond the current string pointer. However, the check to see whether or not this can be done is incorrect; "size" is used whereas "size_" should be used. Therefore, an attacker can call Update with a string of certain length and cause the current string to have other data appended to it. In the case of HTTP being parsed out of incoming socket data, this can be incoming data from other sockets. + +

+

Normally node::StringPtr::Save, which is called after each execution of `http_parser`, would stop this from being exploitable as it converts strings to non-optimizable heap-based strings. However, this is not done to 0-length strings. An attacker can therefore exploit the mistake by making Update set a 0-length string, and then Update past its boundary, so long as it is done in one `http_parser` execution. This can be done with an HTTP header with empty value, followed by a continuation with a value of certain length. + +

+

The attached files demonstrate the issue:

+
$ ./node ~/stringptr-update-poc-server.js &
+[1] 11801
+$ ~/stringptr-update-poc-client.py
+HTTP/1.1 200 OK
+Content-Type: text/plain
+Date: Wed, 18 Apr 2012 00:05:11 GMT
+Connection: close
+Transfer-Encoding: chunked
+
+64
+X header:
+ This is private data, perhaps an HTTP request with a Cookie in it.
+0
+
+

The fix landed on 7b3fb22 and c9a231d, for master and v0.6, respectively. The innocuous commit message does not give away the security implications, precisely because we wanted to get a fix out before making a big deal about it.

+

The first releases with the fix are v0.7.8 and 0.6.17. So now is a good time to make a big deal about it.

+

If you are using node version 0.6 in production, please upgrade to at least v0.6.17, or at least apply the fix in c9a231d to your system. (Version 0.6.17 also fixes some other important bugs, and is without doubt the most stable release of Node 0.6 to date, so it's a good idea to upgrade anyway.)

+

I'm extremely grateful that Matthew took the time to report the problem to us with such an elegant explanation, and in such a way that we had a reasonable amount of time to fix the issue before making it public.

diff --git a/doc/changelog-foot.html b/doc/changelog-foot.html index cc27eafb5ef..1bb70dfd203 100644 --- a/doc/changelog-foot.html +++ b/doc/changelog-foot.html @@ -15,22 +15,21 @@
  • -

    Copyright Joyent, Inc, Node.js is a trademark of Joyent, Inc. View license.

    +

    Copyright Joyent, Inc, Node.js is a trademark of Joyent, Inc. View license.

    - diff --git a/doc/community/index.html b/doc/community/index.html index c6605c07408..b5cbc73223b 100644 --- a/doc/community/index.html +++ b/doc/community/index.html @@ -42,10 +42,10 @@ - +

    Node's most valuable feature is the friendly and colorful community of developers. There are many places where this group congregates on the internet. This page attempts to highlight the best forums.

    - +

    Documentation

    @@ -54,7 +54,7 @@

    Documentation

    Node Manual offers stylized API docs, as well as tutorials and live code samples

    Node Bits provides sample Node.js projects

    docs.nodejitsu.com answers many of the common problems people come across.

    -

    How To Node has a growing number of useful tutorials.

    +

    How To Node has a growing number of useful tutorials.

    Stack Overflow node.js tag collects new information every day.

    @@ -77,7 +77,7 @@

    GitHub

    - +

    Mailing Lists

    @@ -169,7 +169,7 @@

    IRC

    channel for those who miss a day.

    - +

    @@ -188,19 +188,17 @@

    IRC

  • -

    Copyright Joyent, Inc, Node.js is a trademark of Joyent, Inc. View license.

    +

    Copyright Joyent, Inc, Node.js is a trademark of Joyent, Inc. View license.

    - diff --git a/doc/images/forkme.png b/doc/images/forkme.png new file mode 100644 index 00000000000..be10e2109e4 Binary files /dev/null and b/doc/images/forkme.png differ diff --git a/doc/index.html b/doc/index.html index 9f61fd1fff9..6c1c82dcd88 100644 --- a/doc/index.html +++ b/doc/index.html @@ -31,9 +31,9 @@ Download Docs -

    __VERSION__

    +

    __VERSION__

    - Fork me on GitHub + Fork me on GitHub

    Node.js in the Industry

    @@ -43,9 +43,10 @@

    Node.js in the Industry

    experience for the development of a whole new class of real-time applications.
    - Claudio Caldato + Claudio Caldato
    - Principal Program Manager, Interoperability Strategy

    + Principal Program Manager, Microsoft Open Technologies, Inc.

    +
  • Node’s evented I/O model freed us from worrying about locking @@ -80,7 +81,7 @@

    Node.js in the Industry

    X @@ -88,6 +89,7 @@

    Node.js in the Industry

  • Change Log
  • Documentation
  • Other release files
  • +
  • Windows x64 Installer
  • License
  • Git Repository
  • Installing @@ -213,7 +215,7 @@

    Explore Node.js

    -

    Copyright Joyent, Inc, Node.js is a trademark of Joyent, Inc. View license.

    +

    Copyright Joyent, Inc, Node.js is a trademark of Joyent, Inc. View license.

  • @@ -222,15 +224,13 @@

    Explore Node.js

    - diff --git a/doc/logos/index.html b/doc/logos/index.html index 02b933052dc..62e308229aa 100644 --- a/doc/logos/index.html +++ b/doc/logos/index.html @@ -40,7 +40,7 @@ - +

    Logo Downloads

    @@ -82,19 +82,17 @@

    Desktop Background

  • -

    Copyright Joyent, Inc., Node.js is a trademark of Joyent, Inc., View License

    +

    Copyright Joyent, Inc., Node.js is a trademark of Joyent, Inc., View License

    - diff --git a/doc/node.1 b/doc/node.1 index f17ccdae1a3..9603a91ef03 100644 --- a/doc/node.1 +++ b/doc/node.1 @@ -41,6 +41,26 @@ focused on creating simple, easy to build network clients and servers. +.SH OPTIONS + + -v, --version print node's version + + -e, --eval script evaluate script + + -p, --print print result of --eval + + -i, --interactive always enter the REPL even if stdin + does not appear to be a terminal + + --no-deprecation silence deprecation warnings + + --trace-deprecation show stack traces on deprecations + + --v8-options print v8 command line options + + --max-stack-size=val set max v8 stack size (bytes) + + .SH ENVIRONMENT VARIABLES .IP NODE_PATH @@ -54,30 +74,38 @@ If set to 1 then colors will not be used in the REPL. .SH V8 OPTIONS + --use_strict (enforce strict mode) + type: bool default: false + --es5_readonly (activate correct semantics for inheriting readonliness) + type: bool default: false + --es52_globals (activate new semantics for global var declarations) + type: bool default: false --harmony_typeof (enable harmony semantics for typeof) type: bool default: false + --harmony_scoping (enable harmony block scoping) + type: bool default: false + --harmony_modules (enable harmony modules (implies block scoping)) + type: bool default: false --harmony_proxies (enable harmony proxies) type: bool default: false - --harmony_weakmaps (enable harmony weak maps) + --harmony_collections (enable harmony collections (sets, maps, and weak maps)) type: bool default: false - --harmony_block_scoping (enable harmony block scoping) + --harmony (enable all harmony features (except typeof)) type: bool default: false - --unbox_double_arrays (automatically unbox arrays of doubles) - type: bool default: true - --string_slices (use string slices) + --packed_arrays (optimizes arrays that have no holes) type: bool default: false - --crankshaft (use crankshaft) + --smi_only_arrays (tracks arrays with only smi values) type: bool default: true - --hydrogen_filter (hydrogen use/trace filter) - type: string default: - --use_hydrogen (use generated hydrogen for compilation) + --clever_optimizations (Optimize object size, Array shift, DOM strings and string +) type: bool default: true - --build_lithium (use lithium chunk builder) + --unbox_double_arrays (automatically unbox arrays of doubles) type: bool default: true - --alloc_lithium (use lithium register allocator) + --string_slices (use string slices) type: bool default: true - --use_lithium (use lithium code generator) + --crankshaft (use crankshaft) type: bool default: true + --hydrogen_filter (optimization filter) + type: string default: --use_range (use hydrogen range analysis) type: bool default: true --eliminate_dead_phis (eliminate dead phis) @@ -88,16 +116,22 @@ If set to 1 then colors will not be used in the REPL. type: bool default: true --use_inlining (use function inlining) type: bool default: true - --limit_inlining (limit code size growth from inlining) - type: bool default: true - --eliminate_empty_blocks (eliminate empty blocks) - type: bool default: true + --max_inlined_source_size (maximum source size in bytes considered for a single inlining) + type: int default: 600 + --max_inlined_nodes (maximum number of AST nodes considered for a single inlining) + type: int default: 196 + --max_inlined_nodes_cumulative (maximum cumulative number of AST nodes considered for inlining) + type: int default: 196 --loop_invariant_code_motion (loop invariant code motion) type: bool default: true + --collect_megamorphic_maps_from_stub_cache (crankshaft harvests type feedback from stub cache) + type: bool default: true --hydrogen_stats (print statistics for hydrogen) type: bool default: false --trace_hydrogen (trace generated hydrogen to file) type: bool default: false + --trace_phase (trace generated IR for specified phases) + type: string default: Z --trace_inlining (trace inlining decisions) type: bool default: false --trace_alloc (trace register allocator) @@ -124,18 +158,54 @@ If set to 1 then colors will not be used in the REPL. type: bool default: true --use_osr (use on-stack replacement) type: bool default: true + --array_bounds_checks_elimination (perform array bounds checks elimination) + type: bool default: false + --array_index_dehoisting (perform array index dehoisting) + type: bool default: false --trace_osr (trace on-stack replacement) type: bool default: false --stress_runs (number of stress runs) type: int default: 0 --optimize_closures (optimize closures) type: bool default: true + --inline_construct (inline constructor calls) + type: bool default: true + --inline_arguments (inline functions with arguments object) + type: bool default: true + --loop_weight (loop weight for representation inference) + type: int default: 1 + --optimize_for_in (optimize functions containing for-in loops) + type: bool default: true + --experimental_profiler (enable all profiler experiments) + type: bool default: true + --watch_ic_patching (profiler considers IC stability) + type: bool default: false + --frame_count (number of stack frames inspected by the profiler) + type: int default: 1 + --self_optimization (primitive functions trigger their own optimization) + type: bool default: false + --direct_self_opt (call recompile stub directly when self-optimizing) + type: bool default: false + --retry_self_opt (re-try self-optimization if it failed) + type: bool default: false + --count_based_interrupts (trigger profiler ticks based on counting instead of timing) + type: bool default: false + --interrupt_at_exit (insert an interrupt check at function exit) + type: bool default: false + --weighted_back_edges (weight back edges by jump distance for interrupt triggering) + type: bool default: false + --interrupt_budget (execution budget before interrupt is triggered) + type: int default: 5900 + --type_info_threshold (percentage of ICs that must have type info to allow optimization) + type: int default: 15 + --self_opt_count (call count before self-optimization) + type: int default: 130 + --trace_opt_verbose (extra verbose compilation tracing) + type: bool default: false --debug_code (generate extra code (assertions) for debugging) type: bool default: false --code_comments (emit comments in code disassembly) type: bool default: false - --peephole_optimization (perform peephole optimizations in assembly code) - type: bool default: true --enable_sse2 (enable use of SSE2 instructions if available) type: bool default: true --enable_sse3 (enable use of SSE3 instructions if available) @@ -164,6 +234,8 @@ If set to 1 then colors will not be used in the REPL. type: bool default: false --stack_trace_limit (number of stack frames to capture) type: int default: 10 + --builtins_in_stack_traces (show built-in functions in stack traces) + type: bool default: false --disable_native_files (disable builtin natives files) type: bool default: false --inline_new (use fast inline allocation) @@ -182,14 +254,10 @@ If set to 1 then colors will not be used in the REPL. type: bool default: false --opt (use adaptive optimizations) type: bool default: true - --opt_eagerly (be more eager when adaptively optimizing) - type: bool default: false --always_opt (always try to optimize functions) type: bool default: false --prepare_always_opt (prepare for turning on always opt) type: bool default: false - --deopt (support deoptimization) - type: bool default: true --trace_deopt (trace deoptimization) type: bool default: false --min_preparse_length (minimum length for automatic enable preparsing) @@ -208,8 +276,10 @@ If set to 1 then colors will not be used in the REPL. type: bool default: true --enable_liveedit (enable liveedit experimental feature) type: bool default: true - --stack_size (default size of stack region v8 is allowed to use (in KkBytes)) - type: int default: 1024 + --break_on_abort (always cause a debug break before aborting) + type: bool default: true + --stack_size (default size of stack region v8 is allowed to use (in kBytes)) + type: int default: 984 --max_stack_trace_source_length (maximum length of function source code printed in a stack trace.) type: int default: 300 --always_inline_smi_code (always inline smi code in non-opt code) @@ -232,43 +302,45 @@ If set to 1 then colors will not be used in the REPL. type: bool default: false --trace_gc_verbose (print more details following each garbage collection) type: bool default: false + --trace_fragmentation (report fragmentation for old pointer and data pages) + type: bool default: false --collect_maps (garbage collect maps from which no objects can be reached) type: bool default: true --flush_code (flush code that we expect not to use again before full gc) type: bool default: true + --incremental_marking (use incremental marking) + type: bool default: true + --incremental_marking_steps (do incremental marking steps) + type: bool default: true + --trace_incremental_marking (trace progress of the incremental marking) + type: bool default: false --use_idle_notification (Use idle notification to reduce memory footprint.) type: bool default: true + --send_idle_notification (Send idle notifcation between stress runs.) + type: bool default: false --use_ic (use inline caching) type: bool default: true --native_code_counters (generate extra code for manipulating stats counters) type: bool default: false --always_compact (Perform compaction on every full GC) type: bool default: false + --lazy_sweeping (Use lazy sweeping for old pointer and data spaces) + type: bool default: true --never_compact (Never perform compaction on full GC - testing only) type: bool default: false + --compact_code_space (Compact code space on full non-incremental collections) + type: bool default: true --cleanup_code_caches_at_gc (Flush inline caches prior to mark compact collection and flush code caches in maps during mark compact cycle.) type: bool default: true --random_seed (Default seed for initializing random generator (0, the default, means to use system random).) type: int default: 0 - --canonicalize_object_literal_maps (Canonicalize maps for object literals.) - type: bool default: true - --use_big_map_space (Use big map space, but don't compact if it grew too big.) - type: bool default: true - --max_map_space_pages (Maximum number of pages in map space which still allows to encode forwarding pointers. That's actually a constant, but it's useful to control it with a flag for better testing.) - type: int default: 65535 - --h (print this message) - type: bool default: false - --new_snapshot (use new snapshot implementation) - type: bool default: true --use_verbose_printer (allows verbose printing) type: bool default: true --allow_natives_syntax (allow natives syntax) type: bool default: false - --strict_mode (allow strict mode directives) - type: bool default: true --trace_sim (Trace simulator execution) type: bool default: false - --check_icache (Check icache flushes in ARM simulator) + --check_icache (Check icache flushes in ARM and MIPS simulator) type: bool default: false --stop_sim_at (Simulator stop after x number of instructions) type: int default: 0 @@ -286,8 +358,6 @@ If set to 1 then colors will not be used in the REPL. type: bool default: false --regexp_optimization (generate optimized regexp code) type: bool default: true - --regexp_entry_native (use native code to enter regexp) - type: bool default: true --testing_bool_flag (testing_bool_flag) type: bool default: true --testing_int_flag (testing_int_flag) @@ -313,9 +383,9 @@ If set to 1 then colors will not be used in the REPL. --debugger_port (Port to use for remote debugging) type: int default: 5858 --map_counters (Map counters to a file) - type: string default: + type: string default: --js_arguments (Pass all remaining arguments to the script. Alias for "--".) - type: arguments default: + type: arguments default: --debug_compile_events (Enable debugger compile events) type: bool default: true --debug_script_collected_events (Enable debugger script collected events) @@ -327,66 +397,10 @@ If set to 1 then colors will not be used in the REPL. --gdbjit_dump (dump elf objects with debug info to disk) type: bool default: false --gdbjit_dump_filter (dump only objects containing this substring) - type: string default: - --enable_slow_asserts (enable asserts that are slow to execute) - type: bool default: false - --trace_codegen (print name of functions for which code is generated) - type: bool default: false - --print_source (pretty print source code) - type: bool default: false - --print_builtin_source (pretty print source code for builtins) - type: bool default: false - --print_ast (print source AST) - type: bool default: false - --print_builtin_ast (print source AST for builtins) - type: bool default: false - --print_json_ast (print source AST as JSON) - type: bool default: false - --print_builtin_json_ast (print source AST for builtins as JSON) - type: bool default: false - --stop_at (function name where to insert a breakpoint) - type: string default: - --verify_stack_height (verify stack height tracing on ia32) - type: bool default: false - --print_builtin_scopes (print scopes for builtins) - type: bool default: false - --print_scopes (print scopes) - type: bool default: false - --trace_contexts (trace contexts operations) + type: string default: + --force_marking_deque_overflows (force overflows of marking deque by reducing it's size to 64 words) type: bool default: false - --gc_greedy (perform GC prior to some allocations) - type: bool default: false - --gc_verbose (print stuff during garbage collection) - type: bool default: false - --heap_stats (report heap statistics before and after GC) - type: bool default: false - --code_stats (report code statistics after GC) - type: bool default: false - --verify_heap (verify heap pointers before and after GC) - type: bool default: false - --print_handles (report handles after GC) - type: bool default: false - --print_global_handles (report global handles after GC) - type: bool default: false - --trace_ic (trace inline cache state transitions) - type: bool default: false - --trace_normalization (prints when objects are turned into dictionaries.) - type: bool default: false - --trace_lazy (trace lazy compilation) - type: bool default: false - --debug_serialization (write debug information into the snapshot.) - type: bool default: false - --collect_heap_spill_statistics (report heap spill statistics along with heap_stats (requires heap_stats)) - type: bool default: false - --trace_isolates (trace isolate state changes) - type: bool default: false - --log_state_changes (Log state changes.) - type: bool default: false - --regexp_possessive_quantifier (enable possessive quantifier syntax for testing) - type: bool default: false - --trace_regexp_bytecodes (trace regexp bytecode execution) - type: bool default: false - --trace_regexp_assembler (trace regexp macro assembler calls.) + --stress_compaction (stress the GC compactor to flush out bugs (implies --force_marking_deque_overflows)) type: bool default: false --log (Minimal logging (no API, code, GC, suspect, or handles samples).) type: bool default: false @@ -422,19 +436,6 @@ If set to 1 then colors will not be used in the REPL. type: string default: v8.log --ll_prof (Enable low-level linux profiler.) type: bool default: false - --print_code_stubs (print code stubs) - type: bool default: false - --print_code (print generated code) - type: bool default: false - --print_opt_code (print optimized code) - type: bool default: false - --print_unopt_code (print unoptimized code before printing optimized code based on it) - type: bool default: false - --print_code_verbose (print more information for code) - type: bool default: false - --print_builtin_code (print generated code for builtins) - type: bool default: false - .SH RESOURCES AND DOCUMENTATION diff --git a/doc/rss.xml b/doc/rss.xml new file mode 100644 index 00000000000..a96aa78f729 --- /dev/null +++ b/doc/rss.xml @@ -0,0 +1,45 @@ + + + + + Node.js Blog + + http://blog.nodejs.org/ + The Blog about Node.js + <%= new Date().toUTCString() %> + en + weekly + 1 + http://nodejs.org/ + + http://nodejs.org/images/logo-light.png + Node.js + http://blog.nodejs.org/ + + <% + posts.forEach(function(post) { + %> + + <%= post.title %> + http://blog.nodejs.org<%= post.permalink %> + <%= post.date.toUTCString() %> + <%= post.author %> + ]]> + + http://blog.nodejs.org<%= post.permalink %> + ]]> + ]]> + + <% + }); + %> + + diff --git a/doc/template.html b/doc/template.html index 93edf4934c3..d6aa074a9a4 100644 --- a/doc/template.html +++ b/doc/template.html @@ -66,21 +66,20 @@

    Table of Contents

  • -

    Copyright Joyent, Inc, Node.js is a trademark of Joyent, Inc. View license.

    +

    Copyright Joyent, Inc, Node.js is a trademark of Joyent, Inc. View license.

    - diff --git a/lib/buffer.js b/lib/buffer.js index 7a65fa13c79..53f484c56dc 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -210,8 +210,12 @@ function Buffer(subject, encoding, offset) { // Are we slicing? if (typeof offset === 'number') { + if (!Buffer.isBuffer(subject)) { + throw new Error('First argument must be a Buffer when slicing'); + } + this.length = coerce(encoding); - this.parent = subject; + this.parent = subject.parent ? subject.parent : subject; this.offset = offset; } else { // Find the length @@ -469,6 +473,38 @@ Buffer.prototype.fill = function fill(value, start, end) { }; +Buffer.concat = function(list, length) { + if (!Array.isArray(list)) { + throw new Error('Usage: Buffer.concat(list, [length])'); + } + + if (list.length === 0) { + return new Buffer(0); + } else if (list.length === 1) { + return list[0]; + } + + if (typeof length !== 'number') { + length = 0; + for (var i = 0; i < list.length; i++) { + var buf = list[i]; + length += buf.length; + } + } + + var buffer = new Buffer(length); + var pos = 0; + for (var i = 0; i < list.length; i++) { + var buf = list[i]; + buf.copy(buffer, pos); + pos += buf.length; + } + return buffer; +}; + + + + // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length) Buffer.prototype.copy = function(target, target_start, start, end) { var source = this; diff --git a/lib/child_process.js b/lib/child_process.js index f79481dcfe2..34edbc25ad0 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -160,6 +160,8 @@ var handleConversion = { // This object keep track of the socket there are sended function SocketListSend(slave, key) { + EventEmitter.call(this); + var self = this; this.key = key; @@ -201,6 +203,8 @@ SocketListSend.prototype.update = function() { // This object keep track of the socket there are received function SocketListReceive(slave, key) { + EventEmitter.call(this); + var self = this; this.key = key; @@ -329,11 +333,6 @@ function setupChannel(target, channel) { return; } - // For overflow protection don't write if channel queue is too deep. - if (channel.writeQueueSize > 1024 * 1024) { - return false; - } - // package messages with a handle object if (handle) { // this message will be handled by an internalMessage event handler @@ -379,7 +378,8 @@ function setupChannel(target, channel) { writeReq.oncomplete = nop; - return true; + /* If the master is > 2 read() calls behind, please stop sending. */ + return channel.writeQueueSize < (65536 * 2); }; target.connected = true; @@ -437,7 +437,8 @@ exports.fork = function(modulePath /*, args, options*/) { // Leave stdin open for the IPC channel. stdout and stderr should be the // same as the parent's if silent isn't set. - options.stdio = options.silent ? ['ipc', 'pipe', 'pipe'] : ['ipc', 1, 2]; + options.stdio = options.silent ? ['pipe', 'pipe', 'pipe', 'ipc'] : + [0, 1, 2, 'ipc']; return spawn(process.execPath, args, options); }; @@ -540,12 +541,24 @@ exports.execFile = function(file /* args, options, callback */) { } } + function errorhandler(e) { + err = e; + child.stdout.destroy(); + child.stderr.destroy(); + exithandler(); + } + function kill() { + child.stdout.destroy(); + child.stderr.destroy(); + killed = true; - child.kill(options.killSignal); - process.nextTick(function() { - exithandler(null, options.killSignal); - }); + try { + child.kill(options.killSignal); + } catch (e) { + err = e; + exithandler(); + } } if (options.timeout > 0) { @@ -575,6 +588,7 @@ exports.execFile = function(file /* args, options, callback */) { }); child.addListener('close', exithandler); + child.addListener('error', errorhandler); return child; }; @@ -602,6 +616,7 @@ var spawn = exports.spawn = function(file, args, options) { args: args, cwd: options ? options.cwd : null, windowsVerbatimArguments: !!(options && options.windowsVerbatimArguments), + detached: !!(options && options.detached), envPairs: envPairs, stdio: options ? options.stdio : null, uid: options ? options.uid : null, @@ -622,6 +637,8 @@ function maybeClose(subprocess) { function ChildProcess() { + EventEmitter.call(this); + var self = this; this._closesNeeded = 1; @@ -825,23 +842,51 @@ function errnoException(errorno, syscall, errmsg) { ChildProcess.prototype.kill = function(sig) { + var signal; + if (!constants) { constants = process.binding('constants'); } - sig = sig || 'SIGTERM'; - var signal = constants[sig]; + if (sig === 0) { + signal = 0; + } else if (!sig) { + signal = constants['SIGTERM']; + } else { + signal = constants[sig]; + } - if (!signal) { + if (signal === undefined) { throw new Error('Unknown signal: ' + sig); } if (this._handle) { - this.killed = true; var r = this._handle.kill(signal); - if (r === -1) { + if (r == 0) { + /* Success. */ + this.killed = true; + return true; + } else if (errno == 'ESRCH') { + /* Already dead. */ + } else if (errno == 'EINVAL' || errno == 'ENOSYS') { + /* The underlying platform doesn't support this signal. */ + throw errnoException(errno, 'kill'); + } else { + /* Other error, almost certainly EPERM. */ this.emit('error', errnoException(errno, 'kill')); - return; } } + + /* Kill didn't succeed. */ + return false; +}; + + +ChildProcess.prototype.ref = function() { + if (this._handle) this._handle.ref(); +}; + + +ChildProcess.prototype.unref = function() { + if (this._handle) this._handle.unref(); }; diff --git a/lib/cluster.js b/lib/cluster.js index c260b639fa3..da1eb0f0214 100644 --- a/lib/cluster.js +++ b/lib/cluster.js @@ -144,7 +144,7 @@ function sendInternalMessage(worker, message/*, handler, callback*/) { // Store callback for later if (callback) { - message._requestEcho = worker.uniqueID + ':' + (++queryIds); + message._requestEcho = worker.id + ':' + (++queryIds); queryCallbacks[message._requestEcho] = callback; } @@ -172,8 +172,13 @@ if (isWorker) { // the worker representation inside a worker function Worker() { - this.uniqueID = toDecInt(process.env.NODE_UNIQUE_ID); - + EventEmitter.call(this); + + this.id = toDecInt(process.env.NODE_UNIQUE_ID); + + // XXX: Legacy. Remove in 0.9 + this.workerID = this.uniqueID = this.id; + // handle internalMessage and exit event process.on('internalMessage', handleMessage.bind(null, this)); @@ -263,12 +268,12 @@ if (isWorker) { }; // Internal function. Called by lib/net.js when attempting to bind a server. - cluster._getServer = function(tcpSelf, address, port, addressType, cb) { + cluster._getServer = function(tcpSelf, address, port, addressType, fd, cb) { // This can only be called from a worker. assert(cluster.isWorker); // Store tcp instance for later use - var key = [address, port, addressType].join(':'); + var key = [address, port, addressType, fd].join(':'); serverListeners[key] = tcpSelf; // Send a listening message to the master @@ -278,7 +283,8 @@ if (isWorker) { cmd: 'listening', address: address, port: port, - addressType: addressType + addressType: addressType, + fd: fd }); }); @@ -287,7 +293,8 @@ if (isWorker) { cmd: 'queryServer', address: address, port: port, - addressType: addressType + addressType: addressType, + fd: fd }; // The callback will be stored until the master has responded @@ -306,20 +313,24 @@ if (isWorker) { // Create a worker object, that works both for master and worker function Worker(master, customEnv, id) { - + EventEmitter.call(this); + var self = this; var env = process.env; this.master = master; - this.uniqueID = id; + this.id = id; + + // XXX: Legacy. Remove in 0.9 + this.workerID = this.uniqueID = this.id; // Assign state this.state = 'none'; // Create env object - // first: copy and add uniqueID + // first: copy and add id property var envCopy = util._extend({}, env); - envCopy['NODE_UNIQUE_ID'] = this.uniqueID; + envCopy['NODE_UNIQUE_ID'] = this.id; // second: extend envCopy with the env argument if (isObject(customEnv)) { envCopy = util._extend(envCopy, customEnv); @@ -363,7 +374,7 @@ if (isWorker) { this.suicide = !!this.suicide; // Remove from workers in the master - delete this.master.workers[this.uniqueID]; + delete this.master.workers[this.id]; }; Worker.prototype.destroy = function() { @@ -421,6 +432,7 @@ if (isWorker) { }); function Master() { + EventEmitter.call(this); this._started = false; this._serverHandles = {}; // Settings object @@ -502,13 +514,13 @@ if (isWorker) { progress.check(); }; - Master.prototype._getServerHandle = function (address, port, addressType) { - var key = address + ':' + port + ':' + addressType; + Master.prototype._getServerHandle = function (address, port, addressType, fd) { + var key = address + ':' + port + ':' + addressType + ':' + fd; if (this._serverHandles.hasOwnProperty(key)) { return this._serverHandles[key]; } else { - return this._serverHandles[key] = net._createServerHandle(address, port, addressType); + return this._serverHandles[key] = net._createServerHandle(address, port, addressType, fd); } }; @@ -539,12 +551,14 @@ if (isWorker) { worker.emit('listening', { address: message.address, port: message.port, - addressType: message.addressType + addressType: message.addressType, + fd: message.fd }); worker.master.emit('listening', worker, { address: message.address, port: message.port, addressType: message.addressType + fd: message.fd }); }; diff --git a/lib/domain.js b/lib/domain.js index e865a1faa05..7c4a85226ad 100644 --- a/lib/domain.js +++ b/lib/domain.js @@ -53,7 +53,7 @@ function uncaughtHandler(er) { // if there's an active domain, then handle this there. // Note that if this error emission throws, then it'll just crash. if (exports.active && !exports.active._disposed) { - decorate(er, { + util._extend(er, { domain: exports.active, domain_thrown: true }); @@ -136,7 +136,7 @@ Domain.prototype.remove = function(ee) { }; Domain.prototype.run = function(fn) { - this.bind(fn)(); + return this.bind(fn)(); }; Domain.prototype.intercept = function(cb) { @@ -158,7 +158,7 @@ Domain.prototype.bind = function(cb, interceptError) { if (interceptError && arguments[0] && (arguments[0] instanceof Error)) { var er = arguments[0]; - decorate(er, { + util._extend(er, { domain_bound: cb, domain_thrown: false, domain: self @@ -167,6 +167,34 @@ Domain.prototype.bind = function(cb, interceptError) { return; } + // remove first-arg if intercept as assumed to be the error-arg + if (interceptError) { + var len = arguments.length; + var args; + switch (len) { + case 0: + case 1: + // no args that we care about. + args = []; + break; + case 2: + // optimization for most common case: cb(er, data) + args = [arguments[1]]; + break; + default: + // slower for less common case: cb(er, foo, bar, baz, ...) + args = new Array(len - 1); + for (var i = 1; i < len; i++) { + args[i] = arguments[i - 1]; + } + break; + } + self.enter(); + var ret = cb.apply(this, args); + self.exit(); + return ret; + } + self.enter(); var ret = cb.apply(this, arguments); self.exit(); @@ -223,11 +251,3 @@ Domain.prototype.dispose = function() { // so that it can't be entered or activated. this._disposed = true; }; - - -function decorate(er, props) { - Object.keys(props).forEach(function(k, _, __) { - if (er.hasOwnProperty(k)) return; - er[k] = props[k]; - }); -} diff --git a/lib/events.js b/lib/events.js index c4ab9d80a0a..7e219a14a4a 100644 --- a/lib/events.js +++ b/lib/events.js @@ -20,11 +20,12 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. var isArray = Array.isArray; +var domain; function EventEmitter() { if (exports.usingDomains) { // if there is an active domain, then attach to it. - var domain = require('domain'); + domain = domain || require('domain'); if (domain.active && !(this instanceof domain.Domain)) { this.domain = domain.active; } @@ -228,15 +229,8 @@ EventEmitter.prototype.removeAllListeners = function(type) { return this; } - var events = this._events && this._events[type]; - if (!events) return this; - - if (isArray(events)) { - events.splice(0); - } else { - this._events[type] = null; - } - + // does not use listeners(), so no side effect of creating _events[type] + if (type && this._events && this._events[type]) this._events[type] = null; return this; }; diff --git a/lib/fs.js b/lib/fs.js index d1700a978fb..7c622375e3a 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -50,7 +50,7 @@ var O_SYNC = constants.O_SYNC || 0; var O_TRUNC = constants.O_TRUNC || 0; var O_WRONLY = constants.O_WRONLY || 0; -var isWindows = process.platform === 'win32' +var isWindows = process.platform === 'win32'; fs.Stats = binding.Stats; @@ -104,11 +104,12 @@ fs.existsSync = function(path) { fs.readFile = function(path, encoding_) { var encoding = typeof(encoding_) === 'string' ? encoding_ : null; var callback = arguments[arguments.length - 1]; - if (typeof(callback) !== 'function') callback = noop; + if (typeof(callback) !== 'function') callback = function() {}; // first, stat the file, so we know the size. var size; - var buffer; + var buffer; // single buffer with file data + var buffers; // list for when size is unknown var pos = 0; var fd; @@ -120,8 +121,10 @@ fs.readFile = function(path, encoding_) { if (er) return callback(er); size = st.size; if (size === 0) { - buffer = new Buffer(0); - return afterRead(null, 0); + // the kernel lies about many files. + // Go ahead and try to read some bytes. + buffers = []; + return read(); } buffer = new Buffer(size); @@ -130,7 +133,12 @@ fs.readFile = function(path, encoding_) { }); function read() { - fs.read(fd, buffer, pos, size - pos, pos, afterRead); + if (size === 0) { + buffer = new Buffer(8192); + fs.read(fd, buffer, 0, 8192, -1, afterRead); + } else { + fs.read(fd, buffer, pos, size - pos, -1, afterRead); + } } function afterRead(er, bytesRead) { @@ -140,13 +148,30 @@ fs.readFile = function(path, encoding_) { }); } + if (bytesRead === 0) { + return close(); + } + pos += bytesRead; - if (pos === size) close(); - else read(); + if (size !== 0) { + if (pos === size) close(); + else read(); + } else { + // unknown size, just read until we don't get bytes. + buffers.push(buffer.slice(0, bytesRead)); + read(); + } } function close() { fs.close(fd, function(er) { + if (size === 0) { + // collected the data into the buffers list. + buffer = Buffer.concat(buffers, pos); + } else if (pos < size) { + buffer = buffer.slice(0, pos); + } + if (encoding) buffer = buffer.toString(encoding); return callback(er, buffer); }); @@ -165,28 +190,49 @@ fs.readFileSync = function(path, encoding) { if (threw) fs.closeSync(fd); } + var pos = 0; + var buffer; // single buffer with file data + var buffers; // list for when size is unknown + if (size === 0) { - fs.closeSync(fd); - return encoding ? '' : new Buffer(0); + buffers = []; + } else { + buffer = new Buffer(size); } - var buffer = new Buffer(size); - var pos = 0; - - while (pos < size) { + var done = false; + while (!done) { var threw = true; try { - var bytesRead = fs.readSync(fd, buffer, pos, size - pos, pos); + if (size !== 0) { + var bytesRead = fs.readSync(fd, buffer, pos, size - pos, pos); + } else { + // the kernel lies about many files. + // Go ahead and try to read some bytes. + buffer = new Buffer(8192); + var bytesRead = fs.readSync(fd, buffer, 0, 8192, pos); + if (bytesRead) { + buffers.push(buffer.slice(0, bytesRead)); + } + } threw = false; } finally { if (threw) fs.closeSync(fd); } pos += bytesRead; + done = (bytesRead === 0) || (size !== 0 && pos >= size); } fs.closeSync(fd); + if (size === 0) { + // data was collected into the buffers list. + buffer = Buffer.concat(buffers, pos); + } else if (pos < size) { + buffer = buffer.slice(0, pos); + } + if (encoding) buffer = buffer.toString(encoding); return buffer; }; @@ -237,13 +283,27 @@ Object.defineProperty(exports, '_stringToFlags', { value: stringToFlags }); -function noop() {} + +// Ensure that callbacks run in the global context. Only use this function +// for callbacks that are passed to the binding layer, callbacks that are +// invoked from JS already run in the proper scope. +function makeCallback(cb) { + if (typeof cb !== 'function') { + // faster than returning a ref to a global no-op function + return function() {}; + } + + return function() { + return cb.apply(null, arguments); + }; +} + // Yes, the follow could be easily DRYed up but I provide the explicit // list to make the arguments clear. fs.close = function(fd, callback) { - binding.close(fd, callback || noop); + binding.close(fd, makeCallback(callback)); }; fs.closeSync = function(fd) { @@ -264,11 +324,7 @@ function modeNum(m, def) { } fs.open = function(path, flags, mode, callback) { - callback = arguments[arguments.length - 1]; - if (typeof(callback) !== 'function') { - callback = noop; - } - + callback = makeCallback(arguments[arguments.length - 1]); mode = modeNum(mode, 438 /*=0666*/); binding.open(pathModule._makeLong(path), @@ -376,7 +432,7 @@ fs.writeSync = function(fd, buffer, offset, length, position) { fs.rename = function(oldPath, newPath, callback) { binding.rename(pathModule._makeLong(oldPath), pathModule._makeLong(newPath), - callback || noop); + makeCallback(callback)); }; fs.renameSync = function(oldPath, newPath) { @@ -385,7 +441,7 @@ fs.renameSync = function(oldPath, newPath) { }; fs.truncate = function(fd, len, callback) { - binding.truncate(fd, len, callback || noop); + binding.truncate(fd, len, makeCallback(callback)); }; fs.truncateSync = function(fd, len) { @@ -393,7 +449,7 @@ fs.truncateSync = function(fd, len) { }; fs.rmdir = function(path, callback) { - binding.rmdir(pathModule._makeLong(path), callback || noop); + binding.rmdir(pathModule._makeLong(path), makeCallback(callback)); }; fs.rmdirSync = function(path) { @@ -401,7 +457,7 @@ fs.rmdirSync = function(path) { }; fs.fdatasync = function(fd, callback) { - binding.fdatasync(fd, callback || noop); + binding.fdatasync(fd, makeCallback(callback)); }; fs.fdatasyncSync = function(fd) { @@ -409,7 +465,7 @@ fs.fdatasyncSync = function(fd) { }; fs.fsync = function(fd, callback) { - binding.fsync(fd, callback || noop); + binding.fsync(fd, makeCallback(callback)); }; fs.fsyncSync = function(fd) { @@ -418,8 +474,9 @@ fs.fsyncSync = function(fd) { fs.mkdir = function(path, mode, callback) { if (typeof mode === 'function') callback = mode; - binding.mkdir(pathModule._makeLong(path), modeNum(mode, 511 /*=0777*/), - callback || noop); + binding.mkdir(pathModule._makeLong(path), + modeNum(mode, 511 /*=0777*/), + makeCallback(callback)); }; fs.mkdirSync = function(path, mode) { @@ -428,7 +485,7 @@ fs.mkdirSync = function(path, mode) { }; fs.sendfile = function(outFd, inFd, inOffset, length, callback) { - binding.sendfile(outFd, inFd, inOffset, length, callback || noop); + binding.sendfile(outFd, inFd, inOffset, length, makeCallback(callback)); }; fs.sendfileSync = function(outFd, inFd, inOffset, length) { @@ -436,7 +493,7 @@ fs.sendfileSync = function(outFd, inFd, inOffset, length) { }; fs.readdir = function(path, callback) { - binding.readdir(pathModule._makeLong(path), callback || noop); + binding.readdir(pathModule._makeLong(path), makeCallback(callback)); }; fs.readdirSync = function(path) { @@ -444,15 +501,15 @@ fs.readdirSync = function(path) { }; fs.fstat = function(fd, callback) { - binding.fstat(fd, callback || noop); + binding.fstat(fd, makeCallback(callback)); }; fs.lstat = function(path, callback) { - binding.lstat(pathModule._makeLong(path), callback || noop); + binding.lstat(pathModule._makeLong(path), makeCallback(callback)); }; fs.stat = function(path, callback) { - binding.stat(pathModule._makeLong(path), callback || noop); + binding.stat(pathModule._makeLong(path), makeCallback(callback)); }; fs.fstatSync = function(fd) { @@ -468,39 +525,48 @@ fs.statSync = function(path) { }; fs.readlink = function(path, callback) { - binding.readlink(pathModule._makeLong(path), callback || noop); + binding.readlink(pathModule._makeLong(path), makeCallback(callback)); }; fs.readlinkSync = function(path) { return binding.readlink(pathModule._makeLong(path)); }; -fs.symlink = function(destination, path, type_, callback) { - var type = (typeof(type_) == 'string' ? type_ : null); - var callback_ = arguments[arguments.length - 1]; - callback = (typeof(callback_) == 'function' ? callback_ : null); - - if (isWindows && type === 'junction') { - destination = pathModule._makeLong(destination); +function preprocessSymlinkDestination(path, type) { + if (!isWindows) { + // No preprocessing is needed on Unix. + return path; + } else if (type === 'junction') { + // Junctions paths need to be absolute and \\?\-prefixed. + return pathModule._makeLong(path); + } else { + // Windows symlinks don't tolerate forward slashes. + return ('' + path).replace(/\//g, '\\'); } +} + +fs.symlink = function(destination, path, type_, callback) { + var type = (typeof type_ === 'string' ? type_ : null); + var callback = makeCallback(arguments[arguments.length - 1]); - binding.symlink(destination, - pathModule._makeLong(path), type, callback); + binding.symlink(preprocessSymlinkDestination(destination), + pathModule._makeLong(path), + type, + callback); }; fs.symlinkSync = function(destination, path, type) { - if (isWindows && type === 'junction') { - destination = pathModule._makeLong(destination); - } + type = (typeof type === 'string' ? type : null); - return binding.symlink(destination, - pathModule._makeLong(path), type); + return binding.symlink(preprocessSymlinkDestination(destination), + pathModule._makeLong(path), + type); }; fs.link = function(srcpath, dstpath, callback) { binding.link(pathModule._makeLong(srcpath), pathModule._makeLong(dstpath), - callback || noop); + makeCallback(callback)); }; fs.linkSync = function(srcpath, dstpath) { @@ -509,7 +575,7 @@ fs.linkSync = function(srcpath, dstpath) { }; fs.unlink = function(path, callback) { - binding.unlink(pathModule._makeLong(path), callback || noop); + binding.unlink(pathModule._makeLong(path), makeCallback(callback)); }; fs.unlinkSync = function(path) { @@ -517,7 +583,7 @@ fs.unlinkSync = function(path) { }; fs.fchmod = function(fd, mode, callback) { - binding.fchmod(fd, modeNum(mode), callback || noop); + binding.fchmod(fd, modeNum(mode), makeCallback(callback)); }; fs.fchmodSync = function(fd, mode) { @@ -526,7 +592,7 @@ fs.fchmodSync = function(fd, mode) { if (constants.hasOwnProperty('O_SYMLINK')) { fs.lchmod = function(path, mode, callback) { - callback = callback || noop; + callback = callback || (function() {}); fs.open(path, constants.O_WRONLY | constants.O_SYMLINK, function(err, fd) { if (err) { callback(err); @@ -565,7 +631,9 @@ if (constants.hasOwnProperty('O_SYMLINK')) { fs.chmod = function(path, mode, callback) { - binding.chmod(pathModule._makeLong(path), modeNum(mode), callback || noop); + binding.chmod(pathModule._makeLong(path), + modeNum(mode), + makeCallback(callback)); }; fs.chmodSync = function(path, mode) { @@ -574,7 +642,7 @@ fs.chmodSync = function(path, mode) { if (constants.hasOwnProperty('O_SYMLINK')) { fs.lchown = function(path, uid, gid, callback) { - callback = callback || noop; + callback = callback || (function() {}); fs.open(path, constants.O_WRONLY | constants.O_SYMLINK, function(err, fd) { if (err) { callback(err); @@ -591,7 +659,7 @@ if (constants.hasOwnProperty('O_SYMLINK')) { } fs.fchown = function(fd, uid, gid, callback) { - binding.fchown(fd, uid, gid, callback || noop); + binding.fchown(fd, uid, gid, makeCallback(callback)); }; fs.fchownSync = function(fd, uid, gid) { @@ -599,7 +667,7 @@ fs.fchownSync = function(fd, uid, gid) { }; fs.chown = function(path, uid, gid, callback) { - binding.chown(pathModule._makeLong(path), uid, gid, callback || noop); + binding.chown(pathModule._makeLong(path), uid, gid, makeCallback(callback)); }; fs.chownSync = function(path, uid, gid) { @@ -622,9 +690,10 @@ function toUnixTimestamp(time) { fs._toUnixTimestamp = toUnixTimestamp; fs.utimes = function(path, atime, mtime, callback) { - atime = toUnixTimestamp(atime); - mtime = toUnixTimestamp(mtime); - binding.utimes(pathModule._makeLong(path), atime, mtime, callback || noop); + binding.utimes(pathModule._makeLong(path), + toUnixTimestamp(atime), + toUnixTimestamp(mtime), + makeCallback(callback)); }; fs.utimesSync = function(path, atime, mtime) { @@ -636,7 +705,7 @@ fs.utimesSync = function(path, atime, mtime) { fs.futimes = function(fd, atime, mtime, callback) { atime = toUnixTimestamp(atime); mtime = toUnixTimestamp(mtime); - binding.futimes(fd, atime, mtime, callback || noop); + binding.futimes(fd, atime, mtime, makeCallback(callback)); }; fs.futimesSync = function(fd, atime, mtime) { @@ -742,6 +811,8 @@ function errnoException(errorno, syscall) { function FSWatcher() { + EventEmitter.call(this); + var self = this; var FSEvent = process.binding('fs_event_wrap').FSEvent; this._handle = new FSEvent(); @@ -800,10 +871,18 @@ fs.watch = function(filename) { // Stat Change Watchers function StatWatcher() { + EventEmitter.call(this); + var self = this; this._handle = new binding.StatWatcher(); - this._handle.onchange = function(current, previous) { + // uv_fs_poll is a little more powerful than ev_stat but we curb it for + // the sake of backwards compatibility + var oldStatus = -1; + + this._handle.onchange = function(current, previous, newStatus) { + if (oldStatus == -1 && newStatus == -1) return; + oldStatus = newStatus; self.emit('change', current, previous); }; @@ -832,19 +911,21 @@ function inStatWatchers(filename) { fs.watchFile = function(filename) { - if (isWindows) { - throw new Error('use fs.watch api instead'); - } - var stat; - var options; var listener; + var options = { + // Poll interval in milliseconds. 5007 is what libev used to use. It's + // a little on the slow side but let's stick with it for now to keep + // behavioral changes to a minimum. + interval: 5007, + persistent: true + }; + if ('object' == typeof arguments[1]) { - options = arguments[1]; + options = util._extend(options, arguments[1]); listener = arguments[2]; } else { - options = {}; listener = arguments[1]; } @@ -852,9 +933,6 @@ fs.watchFile = function(filename) { throw new Error('watchFile requires a listener function'); } - if (options.persistent === undefined) options.persistent = true; - if (options.interval === undefined) options.interval = 0; - if (inStatWatchers(filename)) { stat = statWatchers[filename]; } else { @@ -880,222 +958,240 @@ fs.unwatchFile = function(filename) { var normalize = pathModule.normalize; +// Regexp that finds the next partion of a (partial) path +// result is [base_with_slash, base], e.g. ['somedir/', 'somedir'] if (isWindows) { - // Node doesn't support symlinks / lstat on windows. Hence realpath is just - // the same as path.resolve that fails if the path doesn't exists. - - // windows version - fs.realpathSync = function realpathSync(p, cache) { - p = pathModule.resolve(p); - if (cache && Object.prototype.hasOwnProperty.call(cache, p)) { - return cache[p]; - } - fs.statSync(p); - if (cache) cache[p] = p; - return p; - }; - - // windows version - fs.realpath = function(p, cache, cb) { - if (typeof cb !== 'function') { - cb = cache; - cache = null; - } - p = pathModule.resolve(p); - if (cache && Object.prototype.hasOwnProperty.call(cache, p)) { - return cb(null, cache[p]); - } - fs.stat(p, function(err) { - if (err) return cb(err); - if (cache) cache[p] = p; - cb(null, p); - }); - }; + var nextPartRe = /(.*?)(?:[\/\\]+|$)/g; +} else { + var nextPartRe = /(.*?)(?:[\/]+|$)/g; +} +// Regex to find the device root, including trailing slash. E.g. 'c:\\'. +if (isWindows) { + var splitRootRe = /^(?:[a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/][^\\\/]+)?[\\\/]*/; +} else { + var splitRootRe = /^[\/]*/; +} -} else /* posix */ { +fs.realpathSync = function realpathSync(p, cache) { + // make p is absolute + p = pathModule.resolve(p); - // Regexp that finds the next partion of a (partial) path - // result is [base_with_slash, base], e.g. ['somedir/', 'somedir'] - var nextPartRe = /(.*?)(?:[\/]+|$)/g; + if (cache && Object.prototype.hasOwnProperty.call(cache, p)) { + return cache[p]; + } - // posix version - fs.realpathSync = function realpathSync(p, cache) { - // make p is absolute - p = pathModule.resolve(p); + var original = p, + seenLinks = {}, + knownHard = {}; + + // current character position in p + var pos; + // the partial path so far, including a trailing slash if any + var current; + // the partial path without a trailing slash (except when pointing at a root) + var base; + // the partial path scanned in the previous round, with slash + var previous; + + start(); + + function start() { + // Skip over roots + var m = splitRootRe.exec(p); + pos = m[0].length; + current = m[0]; + base = m[0]; + previous = ''; + + // On windows, check that the root exists. On unix there is no need. + if (isWindows && !knownHard[base]) { + fs.lstatSync(base); + knownHard[base] = true; + } + } - if (cache && Object.prototype.hasOwnProperty.call(cache, p)) { - return cache[p]; + // walk down the path, swapping out linked pathparts for their real + // values + // NB: p.length changes. + while (pos < p.length) { + // find the next part + nextPartRe.lastIndex = pos; + var result = nextPartRe.exec(p); + previous = current; + current += result[0]; + base = previous + result[1]; + pos = nextPartRe.lastIndex; + + // continue if not a symlink + if (knownHard[base] || (cache && cache[base] === base)) { + continue; } - var original = p, - seenLinks = {}, - knownHard = {}; - - // current character position in p - var pos = 0; - // the partial path so far, including a trailing slash if any - var current = ''; - // the partial path without a trailing slash - var base = ''; - // the partial path scanned in the previous round, with slash - var previous = ''; - - // walk down the path, swapping out linked pathparts for their real - // values - // NB: p.length changes. - while (pos < p.length) { - // find the next part - nextPartRe.lastIndex = pos; - var result = nextPartRe.exec(p); - previous = current; - current += result[0]; - base = previous + result[1]; - pos = nextPartRe.lastIndex; - - // continue if not a symlink, or if root - if (!base || knownHard[base] || (cache && cache[base] === base)) { + var resolvedLink; + if (cache && Object.prototype.hasOwnProperty.call(cache, base)) { + // some known symbolic link. no need to stat again. + resolvedLink = cache[base]; + } else { + var stat = fs.lstatSync(base); + if (!stat.isSymbolicLink()) { + knownHard[base] = true; + if (cache) cache[base] = base; continue; } - var resolvedLink; - if (cache && Object.prototype.hasOwnProperty.call(cache, base)) { - // some known symbolic link. no need to stat again. - resolvedLink = cache[base]; - } else { - var stat = fs.lstatSync(base); - if (!stat.isSymbolicLink()) { - knownHard[base] = true; - if (cache) cache[base] = base; - continue; - } - - // read the link if it wasn't read before + // read the link if it wasn't read before + // dev/ino always return 0 on windows, so skip the check. + var linkTarget = null; + if (!isWindows) { var id = stat.dev.toString(32) + ':' + stat.ino.toString(32); - if (!seenLinks[id]) { - fs.statSync(base); - seenLinks[id] = fs.readlinkSync(base); - resolvedLink = pathModule.resolve(previous, seenLinks[id]); - // track this, if given a cache. - if (cache) cache[base] = resolvedLink; + if (seenLinks.hasOwnProperty(id)) { + linkTarget = seenLinks[id]; } } - - // resolve the link, then start over - p = pathModule.resolve(resolvedLink, p.slice(pos)); - pos = 0; - previous = base = current = ''; + if (linkTarget === null) { + fs.statSync(base); + linkTarget = fs.readlinkSync(base); + } + resolvedLink = pathModule.resolve(previous, linkTarget); + // track this, if given a cache. + if (cache) cache[base] = resolvedLink; + if (!isWindows) seenLinks[id] = linkTarget; } - if (cache) cache[original] = p; + // resolve the link, then start over + p = pathModule.resolve(resolvedLink, p.slice(pos)); + start(); + } - return p; - }; + if (cache) cache[original] = p; + return p; +}; - // posix version - fs.realpath = function realpath(p, cache, cb) { - if (typeof cb !== 'function') { - cb = cache; - cache = null; - } - // make p is absolute - p = pathModule.resolve(p); +fs.realpath = function realpath(p, cache, cb) { + if (typeof cb !== 'function') { + cb = cache; + cache = null; + } + + // make p is absolute + p = pathModule.resolve(p); + + if (cache && Object.prototype.hasOwnProperty.call(cache, p)) { + return process.nextTick(cb.bind(null, null, cache[p])); + } - if (cache && Object.prototype.hasOwnProperty.call(cache, p)) { - return cb(null, cache[p]); + var original = p, + seenLinks = {}, + knownHard = {}; + + // current character position in p + var pos; + // the partial path so far, including a trailing slash if any + var current; + // the partial path without a trailing slash (except when pointing at a root) + var base; + // the partial path scanned in the previous round, with slash + var previous; + + start(); + + function start() { + // Skip over roots + var m = splitRootRe.exec(p); + pos = m[0].length; + current = m[0]; + base = m[0]; + previous = ''; + + // On windows, check that the root exists. On unix there is no need. + if (isWindows && !knownHard[base]) { + fs.lstat(base, function(err) { + if (err) return cb(err); + knownHard[base] = true; + LOOP(); + }); + } else { + process.nextTick(LOOP); } + } - var original = p, - seenLinks = {}, - knownHard = {}; - - // current character position in p - var pos = 0; - // the partial path so far, including a trailing slash if any - var current = ''; - // the partial path without a trailing slash - var base = ''; - // the partial path scanned in the previous round, with slash - var previous = ''; - - // walk down the path, swapping out linked pathparts for their real - // values - LOOP(); - function LOOP() { - // stop if scanned past end of path - if (pos >= p.length) { - if (cache) cache[original] = p; - return cb(null, p); - } + // walk down the path, swapping out linked pathparts for their real + // values + function LOOP() { + // stop if scanned past end of path + if (pos >= p.length) { + if (cache) cache[original] = p; + return cb(null, p); + } - // find the next part - nextPartRe.lastIndex = pos; - var result = nextPartRe.exec(p); - previous = current; - current += result[0]; - base = previous + result[1]; - pos = nextPartRe.lastIndex; - - // continue if known to be hard or if root or in cache already. - if (!base || knownHard[base] || (cache && cache[base] === base)) { - return process.nextTick(LOOP); - } + // find the next part + nextPartRe.lastIndex = pos; + var result = nextPartRe.exec(p); + previous = current; + current += result[0]; + base = previous + result[1]; + pos = nextPartRe.lastIndex; - if (cache && Object.prototype.hasOwnProperty.call(cache, base)) { - // known symbolic link. no need to stat again. - return gotResolvedLink(cache[base]); - } + // continue if not a symlink + if (knownHard[base] || (cache && cache[base] === base)) { + return process.nextTick(LOOP); + } - return fs.lstat(base, gotStat); + if (cache && Object.prototype.hasOwnProperty.call(cache, base)) { + // known symbolic link. no need to stat again. + return gotResolvedLink(cache[base]); } - function gotStat(err, stat) { - if (err) return cb(err); + return fs.lstat(base, gotStat); + } - // if not a symlink, skip to the next path part - if (!stat.isSymbolicLink()) { - knownHard[base] = true; - if (cache) cache[base] = base; - return process.nextTick(LOOP); - } + function gotStat(err, stat) { + if (err) return cb(err); + + // if not a symlink, skip to the next path part + if (!stat.isSymbolicLink()) { + knownHard[base] = true; + if (cache) cache[base] = base; + return process.nextTick(LOOP); + } - // stat & read the link if not read before - // call gotTarget as soon as the link target is known + // stat & read the link if not read before + // call gotTarget as soon as the link target is known + // dev/ino always return 0 on windows, so skip the check. + if (!isWindows) { var id = stat.dev.toString(32) + ':' + stat.ino.toString(32); - if (seenLinks[id]) { + if (seenLinks.hasOwnProperty(id)) { return gotTarget(null, seenLinks[id], base); } - fs.stat(base, function(err) { - if (err) return cb(err); - - fs.readlink(base, function(err, target) { - gotTarget(err, seenLinks[id] = target); - }); - }); } - - function gotTarget(err, target, base) { + fs.stat(base, function(err) { if (err) return cb(err); - var resolvedLink = pathModule.resolve(previous, target); - if (cache) cache[base] = resolvedLink; - gotResolvedLink(resolvedLink); - } + fs.readlink(base, function(err, target) { + if (!isWindows) seenLinks[id] = target; + gotTarget(err, target); + }); + }); + } - function gotResolvedLink(resolvedLink) { + function gotTarget(err, target, base) { + if (err) return cb(err); - // resolve the link, then start over - p = pathModule.resolve(resolvedLink, p.slice(pos)); - pos = 0; - previous = base = current = ''; + var resolvedLink = pathModule.resolve(previous, target); + if (cache) cache[base] = resolvedLink; + gotResolvedLink(resolvedLink); + } - return process.nextTick(LOOP); - } - }; + function gotResolvedLink(resolvedLink) { + // resolve the link, then start over + p = pathModule.resolve(resolvedLink, p.slice(pos)); + start(); + } +}; -} var pool; @@ -1156,7 +1252,7 @@ var ReadStream = fs.ReadStream = function(path, options) { } if (this.fd !== null) { - process.nextTick(function () { + process.nextTick(function() { self._read(); }); return; @@ -1496,6 +1592,8 @@ WriteStream.prototype.destroySoon = WriteStream.prototype.end; // SyncWriteStream is internal. DO NOT USE. // Temporary hack for process.stdout and process.stderr when piped to files. function SyncWriteStream(fd) { + Stream.call(this); + this.fd = fd; this.writable = true; this.readable = false; diff --git a/lib/http.js b/lib/http.js index 92e00049a26..01aa4ebde80 100644 --- a/lib/http.js +++ b/lib/http.js @@ -21,7 +21,7 @@ var util = require('util'); var net = require('net'); -var stream = require('stream'); +var Stream = require('stream'); var url = require('url'); var EventEmitter = require('events').EventEmitter; var FreeList = require('freelist').FreeList; @@ -263,7 +263,7 @@ function utcDate() { /* Abstract base class for ServerRequest and ClientResponse. */ function IncomingMessage(socket) { - stream.Stream.call(this); + Stream.call(this); // TODO Remove one of these eventually. this.socket = socket; @@ -290,7 +290,7 @@ function IncomingMessage(socket) { this.statusCode = null; this.client = this.socket; } -util.inherits(IncomingMessage, stream.Stream); +util.inherits(IncomingMessage, Stream); exports.IncomingMessage = IncomingMessage; @@ -429,7 +429,7 @@ IncomingMessage.prototype._addHeaderLine = function(field, value) { function OutgoingMessage() { - stream.Stream.call(this); + Stream.call(this); this.output = []; this.outputEncodings = []; @@ -447,7 +447,7 @@ function OutgoingMessage() { this.finished = false; } -util.inherits(OutgoingMessage, stream.Stream); +util.inherits(OutgoingMessage, Stream); exports.OutgoingMessage = OutgoingMessage; @@ -705,8 +705,8 @@ OutgoingMessage.prototype.write = function(chunk, encoding) { } if (!this._hasBody) { - console.error('This type of response MUST NOT have a body. ' + - 'Ignoring write() calls.'); + debug('This type of response MUST NOT have a body. ' + + 'Ignoring write() calls.'); return true; } @@ -767,8 +767,8 @@ OutgoingMessage.prototype.end = function(data, encoding) { } if (data && !this._hasBody) { - console.error('This type of response MUST NOT have a body. ' + - 'Ignoring data passed to end().'); + debug('This type of response MUST NOT have a body. ' + + 'Ignoring data passed to end().'); data = false; } @@ -1022,6 +1022,8 @@ ServerResponse.prototype.writeHeader = function() { // concerned with managing a connection pool. function Agent(options) { + EventEmitter.call(this); + var self = this; self.options = options || {}; self.requests = {}; @@ -1791,6 +1793,8 @@ exports._connectionListener = connectionListener; function Client(port, host) { if (!(this instanceof Client)) return new Client(port, host); + EventEmitter.call(this); + host = host || 'localhost'; port = port || 80; this.host = host; @@ -1827,12 +1831,9 @@ Client.prototype.request = function(method, path, headers) { return c; }; -exports.Client = Client; +exports.Client = util.deprecate(Client, + 'http.Client will be removed soon. Do not use it.'); -// TODO http.Client can be removed in v0.9. Until then leave this message. -module.deprecate('Client', 'It will be removed soon. Do not use it.'); - -exports.createClient = function(port, host) { +exports.createClient = util.deprecate(function(port, host) { return new Client(port, host); -}; -module.deprecate('createClient', 'Use `http.request` instead.'); +}, 'http.createClient is deprecated. Use `http.request` instead.'); diff --git a/lib/net.js b/lib/net.js index 16f3f72d984..9f03259d96a 100644 --- a/lib/net.js +++ b/lib/net.js @@ -20,7 +20,7 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. var events = require('events'); -var stream = require('stream'); +var Stream = require('stream'); var timers = require('timers'); var util = require('util'); var assert = require('assert'); @@ -45,7 +45,7 @@ function createTCP() { var FLAG_GOT_EOF = 1 << 0; var FLAG_SHUTDOWN = 1 << 1; var FLAG_DESTROY_SOON = 1 << 2; -var FLAG_SHUTDOWNQUED = 1 << 3; +var FLAG_SHUTDOWN_QUEUED = 1 << 3; var debug; @@ -129,18 +129,11 @@ function initSocketHandle(self) { function Socket(options) { if (!(this instanceof Socket)) return new Socket(options); - stream.Stream.call(this); + Stream.call(this); if (typeof options == 'number') { // Legacy interface. - // Must support legacy interface. Old versions of npm depend on it. - // https://github.com/isaacs/npm/blob/c7824f412f0cb59d6f55cf0bc220253c39e6029f/lib/utils/output.js#L110 var fd = options; - - // Uncomment the following lines after libuv backend is stable and API - // compatibile with legaacy. - // console.error('Deprecated interface net.Socket(fd).'); - // console.trace(); this._handle = createPipe(); this._handle.open(fd); this.readable = this.writable = true; @@ -152,7 +145,7 @@ function Socket(options) { this.allowHalfOpen = options && options.allowHalfOpen; } } -util.inherits(Socket, stream.Stream); +util.inherits(Socket, Stream); exports.Socket = Socket; @@ -236,6 +229,11 @@ Object.defineProperty(Socket.prototype, 'bufferSize', { Socket.prototype.pause = function() { + this._paused = true; + if (this._connecting) { + // will actually pause once the handle is established. + return; + } if (this._handle) { this._handle.readStop(); } @@ -243,6 +241,11 @@ Socket.prototype.pause = function() { Socket.prototype.resume = function() { + this._paused = false; + if (this._connecting) { + // will actually resume once the handle is established. + return; + } if (this._handle) { this._handle.readStart(); } @@ -250,11 +253,11 @@ Socket.prototype.resume = function() { Socket.prototype.end = function(data, encoding) { - if (this._connecting && ((this._flags & FLAG_SHUTDOWNQUED) == 0)) { + if (this._connecting && ((this._flags & FLAG_SHUTDOWN_QUEUED) == 0)) { // still connecting, add data to buffer if (data) this.write(data, encoding); this.writable = false; - this._flags |= FLAG_SHUTDOWNQUED; + this._flags |= FLAG_SHUTDOWN_QUEUED; } if (!this.writable) return; @@ -359,7 +362,9 @@ Socket.prototype._destroy = function(exception, cb) { if (this.server) { this.server._connections--; - this.server._emitCloseIfDrained(); + if (this.server._emitCloseIfDrained) { + this.server._emitCloseIfDrained(); + } } }; @@ -435,6 +440,10 @@ Socket.prototype._getpeername = function() { } if (!this._peername) { this._peername = this._handle.getpeername(); + // getpeername() returns null on error + if (this._peername === null) { + return {}; + } } return this._peername; }; @@ -727,6 +736,12 @@ function afterConnect(status, handle, req, readable, writable) { assert.ok(self._connecting); self._connecting = false; + // now that we're connected, process any pending pause state. + if (self._paused) { + self._paused = false; + self.pause(); + } + if (status == 0) { self.readable = readable; self.writable = writable; @@ -747,9 +762,9 @@ function afterConnect(status, handle, req, readable, writable) { self.emit('connect'); - if (self._flags & FLAG_SHUTDOWNQUED) { + if (self._flags & FLAG_SHUTDOWN_QUEUED) { // end called before connected - call end now with no data - self._flags &= ~FLAG_SHUTDOWNQUED; + self._flags &= ~FLAG_SHUTDOWN_QUEUED; self.end(); } } else { @@ -820,12 +835,33 @@ function toNumber(x) { return (x = Number(x)) >= 0 ? x : false; } var createServerHandle = exports._createServerHandle = - function(address, port, addressType) { + function(address, port, addressType, fd) { var r = 0; // assign handle in listen, and clean up if bind or listen fails var handle; - if (port == -1 && addressType == -1) { + if (typeof fd === 'number' && fd >= 0) { + var tty_wrap = process.binding('tty_wrap'); + var type = tty_wrap.guessHandleType(fd); + switch (type) { + case 'PIPE': + debug('listen pipe fd=' + fd); + // create a PipeWrap + handle = createPipe(); + handle.open(fd); + handle.readable = true; + handle.writable = true; + break; + + default: + // Not a fd we can listen on. This will trigger an error. + debug('listen invalid fd=' + fd + ' type=' + type); + handle = null; + break; + } + return handle; + + } else if (port == -1 && addressType == -1) { handle = createPipe(); if (process.platform === 'win32') { var instances = parseInt(process.env.NODE_PENDING_PIPE_INSTANCES); @@ -855,14 +891,14 @@ var createServerHandle = exports._createServerHandle = }; -Server.prototype._listen2 = function(address, port, addressType, backlog) { +Server.prototype._listen2 = function(address, port, addressType, backlog, fd) { var self = this; var r = 0; // If there is not yet a handle, we need to create one and bind. // In the case of a server sent via IPC, we don't need to do this. if (!self._handle) { - self._handle = createServerHandle(address, port, addressType); + self._handle = createServerHandle(address, port, addressType, fd); if (!self._handle) { process.nextTick(function() { self.emit('error', errnoException(errno, 'listen')); @@ -897,16 +933,16 @@ Server.prototype._listen2 = function(address, port, addressType, backlog) { }; -function listen(self, address, port, addressType, backlog) { +function listen(self, address, port, addressType, backlog, fd) { if (!cluster) cluster = require('cluster'); if (cluster.isWorker) { - cluster._getServer(self, address, port, addressType, function(handle) { + cluster._getServer(self, address, port, addressType, fd, function(handle) { self._handle = handle; - self._listen2(address, port, addressType, backlog); + self._listen2(address, port, addressType, backlog, fd); }); } else { - self._listen2(address, port, addressType, backlog); + self._listen2(address, port, addressType, backlog, fd); } } @@ -932,10 +968,21 @@ Server.prototype.listen = function() { // The port can be found with server.address() listen(self, null, null, backlog); - } else if (arguments[0] instanceof TCP) { - self._handle = arguments[0]; - listen(self, null, -1, -1, backlog); - + } else if (arguments[0] && typeof arguments[0] === 'object') { + var h = arguments[0]; + if (h._handle) { + h = h._handle; + } else if (h.handle) { + h = h.handle; + } + if (h instanceof TCP) { + self._handle = h; + listen(self, null, -1, -1, backlog); + } else if (h.fd && typeof h.fd === 'number' && h.fd >= 0) { + listen(self, null, null, null, backlog, h.fd); + } else { + throw new Error('Invalid listen argument: ' + h); + } } else if (isPipeName(arguments[0])) { // UNIX socket or Windows pipe. var pipeName = self._pipeName = arguments[0]; @@ -1038,9 +1085,9 @@ Server.prototype._emitCloseIfDrained = function() { }; -Server.prototype.listenFD = function(fd, type) { - throw new Error('This API is no longer supported. See child_process.fork'); -}; +Server.prototype.listenFD = util.deprecate(function(fd, type) { + return this.listen({ fd: fd }); +}, 'listenFD is deprecated. Use listen({fd: }).'); // when sending a socket using fork IPC this function is executed Server.prototype._setupSlave = function(socketList) { diff --git a/lib/os.js b/lib/os.js index c21971c84b5..1fe87310333 100644 --- a/lib/os.js +++ b/lib/os.js @@ -20,6 +20,7 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. var binding = process.binding('os'); +var util = require('util'); exports.hostname = binding.getHostname; exports.loadavg = binding.getLoadAvg; @@ -30,17 +31,24 @@ exports.cpus = binding.getCPUs; exports.type = binding.getOSType; exports.release = binding.getOSRelease; exports.networkInterfaces = binding.getInterfaceAddresses; + exports.arch = function() { return process.arch; }; + exports.platform = function() { return process.platform; }; -exports.getNetworkInterfaces = function() { - return exports.networkInterfaces(); +exports.tmpDir = function() { + return process.env.TMPDIR || + process.env.TMP || + process.env.TEMP || + (process.platform === 'win32' ? 'c:\\windows\\temp' : '/tmp'); }; -module.deprecate('getNetworkInterfaces', - 'It is now called `os.networkInterfaces`.'); + +exports.getNetworkInterfaces = util.deprecate(function() { + return exports.networkInterfaces(); +}, 'getNetworkInterfaces is now called `os.networkInterfaces`.'); exports.EOL = process.platform === 'win32' ? '\r\n' : '\n'; diff --git a/lib/path.js b/lib/path.js index 961dc400a53..438b05d8ef6 100644 --- a/lib/path.js +++ b/lib/path.js @@ -21,7 +21,7 @@ var isWindows = process.platform === 'win32'; -var _deprecationWarning = require('util')._deprecationWarning; +var util = require('util'); // resolves . and .. elements in a path array with directory names there @@ -415,16 +415,14 @@ exports.extname = function(path) { }; -exports.exists = function(path, callback) { +exports.exists = util.deprecate(function(path, callback) { require('fs').exists(path, callback); -}; -module.deprecate('exists', 'It is now called `fs.exists`.'); +}, 'path.exists is now called `fs.exists`.'); -exports.existsSync = function(path) { +exports.existsSync = util.deprecate(function(path) { return require('fs').existsSync(path); -}; -module.deprecate('existsSync', 'It is now called `fs.existsSync`.'); +}, 'path.existsSync is now called `fs.existsSync`.'); if (isWindows) { diff --git a/lib/punycode.js b/lib/punycode.js index 887c968b3a4..5ca1254f6ad 100644 --- a/lib/punycode.js +++ b/lib/punycode.js @@ -35,8 +35,6 @@ /** Error messages */ errors = { 'overflow': 'Overflow: input needs wider integers to process.', - 'ucs2decode': 'UCS-2(decode): illegal sequence', - 'ucs2encode': 'UCS-2(encode): illegal value', 'not-basic': 'Illegal input >= 0x80 (not a basic code point)', 'invalid-input': 'Invalid input' }, @@ -112,14 +110,17 @@ extra; while (counter < length) { value = string.charCodeAt(counter++); - if ((value & 0xF800) == 0xD800) { + if ((value & 0xF800) == 0xD800 && counter < length) { + // high surrogate, and there is a next character extra = string.charCodeAt(counter++); - if ((value & 0xFC00) != 0xD800 || (extra & 0xFC00) != 0xDC00) { - error('ucs2decode'); + if ((extra & 0xFC00) == 0xDC00) { // low surrogate + output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000); + } else { + output.push(value, extra); } - value = ((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000; + } else { + output.push(value); } - output.push(value); } return output; } @@ -135,9 +136,6 @@ function ucs2encode(array) { return map(array, function(value) { var output = ''; - if ((value & 0xF800) == 0xD800) { - error('ucs2encode'); - } if (value > 0xFFFF) { value -= 0x10000; output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800); @@ -472,7 +470,7 @@ * @memberOf punycode * @type String */ - 'version': '1.0.0', + 'version': '1.1.1', /** * An object of methods to convert from JavaScript's internal character * representation (UCS-2) to decimal Unicode code points, and back. diff --git a/lib/querystring.js b/lib/querystring.js index 3c03cf313e1..12b6013d525 100644 --- a/lib/querystring.js +++ b/lib/querystring.js @@ -134,42 +134,34 @@ var stringifyPrimitive = function(v) { QueryString.stringify = QueryString.encode = function(obj, sep, eq, name) { sep = sep || '&'; eq = eq || '='; - obj = (obj === null) ? undefined : obj; - - switch (typeof obj) { - case 'object': - return Object.keys(obj).map(function(k) { - if (Array.isArray(obj[k])) { - return obj[k].map(function(v) { - return QueryString.escape(stringifyPrimitive(k)) + - eq + - QueryString.escape(stringifyPrimitive(v)); - }).join(sep); - } else { - return QueryString.escape(stringifyPrimitive(k)) + - eq + - QueryString.escape(stringifyPrimitive(obj[k])); - } - }).join(sep); + if (obj === null) { + obj = undefined; + } + + if (typeof obj === 'object') { + return Object.keys(obj).map(function(k) { + var ks = QueryString.escape(stringifyPrimitive(k)) + eq; + if (Array.isArray(obj[k])) { + return obj[k].map(function(v) { + return ks + QueryString.escape(stringifyPrimitive(v)); + }).join(sep); + } else { + return ks + QueryString.escape(stringifyPrimitive(obj[k])); + } + }).join(sep); - default: - if (!name) return ''; - return QueryString.escape(stringifyPrimitive(name)) + eq + - QueryString.escape(stringifyPrimitive(obj)); } + + if (!name) return ''; + return QueryString.escape(stringifyPrimitive(name)) + eq + + QueryString.escape(stringifyPrimitive(obj)); }; // Parse a key=val string. QueryString.parse = QueryString.decode = function(qs, sep, eq, options) { sep = sep || '&'; eq = eq || '='; - var obj = {}, - maxKeys = 1000; - - // Handle maxKeys = 0 case - if (options && typeof options.maxKeys === 'number') { - maxKeys = options.maxKeys; - } + var obj = {}; if (typeof qs !== 'string' || qs.length === 0) { return obj; @@ -178,19 +170,27 @@ QueryString.parse = QueryString.decode = function(qs, sep, eq, options) { var regexp = /\+/g; qs = qs.split(sep); + var maxKeys = 1000; + if (options && typeof options.maxKeys === 'number') { + maxKeys = options.maxKeys; + } + + var len = qs.length; // maxKeys <= 0 means that we should not limit keys count - if (maxKeys > 0) { - qs = qs.slice(0, maxKeys); + if (maxKeys > 0 && len > maxKeys) { + len = maxKeys; } - for (var i = 0, len = qs.length; i < len; ++i) { + for (var i = 0; i < len; ++i) { var x = qs[i].replace(regexp, '%20'), idx = x.indexOf(eq), - kstr = x.substring(0, idx), - vstr = x.substring(idx + 1), k, v; + kstr, vstr, k, v; - if (kstr === '' && vstr !== '') { - kstr = vstr; + if (idx >= 0) { + kstr = x.substr(0, idx); + vstr = x.substr(idx + 1); + } else { + kstr = x; vstr = ''; } @@ -204,10 +204,10 @@ QueryString.parse = QueryString.decode = function(qs, sep, eq, options) { if (!hasOwnProperty(obj, k)) { obj[k] = v; - } else if (!Array.isArray(obj[k])) { - obj[k] = [obj[k], v]; - } else { + } else if (Array.isArray(obj[k])) { obj[k].push(v); + } else { + obj[k] = [obj[k], v]; } } diff --git a/lib/readline.js b/lib/readline.js index 02d15527cd8..0161b4e292e 100644 --- a/lib/readline.js +++ b/lib/readline.js @@ -49,6 +49,8 @@ function Interface(input, output, completer, terminal) { return new Interface(input, output, completer, terminal); } + EventEmitter.call(this); + if (arguments.length === 1) { // an options object was given output = input.output; @@ -57,8 +59,6 @@ function Interface(input, output, completer, terminal) { input = input.input; } - EventEmitter.call(this); - completer = completer || function() { return []; }; if (typeof completer !== 'function') { @@ -145,7 +145,7 @@ Interface.prototype._setRawMode = function(mode) { if (typeof this.input.setRawMode === 'function') { return this.input.setRawMode(mode); } -} +}; Interface.prototype.prompt = function(preserveCursor) { @@ -188,12 +188,14 @@ Interface.prototype._onLine = function(line) { Interface.prototype._addHistory = function() { if (this.line.length === 0) return ''; - this.history.unshift(this.line); - this.historyIndex = -1; + if (this.history.length === 0 || this.history[0] !== this.line) { + this.history.unshift(this.line); - // Only store so many - if (this.history.length > kHistorySize) this.history.pop(); + // Only store so many + if (this.history.length > kHistorySize) this.history.pop(); + } + this.historyIndex = -1; return this.history[0]; }; @@ -656,8 +658,9 @@ Interface.prototype._ttyWrite = function(s, key) { self.pause(); self.emit('SIGCONT'); } - // explictly re-enable "raw mode" and move the cursor to the correct - // position. See https://github.com/joyent/node/issues/3295. + // explictly re-enable "raw mode" and move the cursor to + // the correct position. + // See https://github.com/joyent/node/issues/3295. self._setRawMode(true); self._refreshLine(); }; @@ -785,10 +788,8 @@ function emitKeypressEvents(stream) { if (stream._emitKeypress) return; stream._emitKeypress = true; - var keypressListeners = stream.listeners('keypress'); - function onData(b) { - if (keypressListeners.length) { + if (stream.listeners('keypress').length > 0) { emitKey(stream, b); } else { // Nobody's watching anyway @@ -804,7 +805,7 @@ function emitKeypressEvents(stream) { } } - if (keypressListeners.length) { + if (stream.listeners('keypress').length > 0) { stream.on('data', onData); } else { stream.on('newListener', onNewListener); diff --git a/lib/repl.js b/lib/repl.js index 26f081ce2fb..c3719ef54eb 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -42,6 +42,7 @@ var util = require('util'); var inherits = require('util').inherits; +var Stream = require('stream'); var vm = require('vm'); var path = require('path'); var fs = require('fs'); @@ -79,6 +80,8 @@ function REPLServer(prompt, stream, eval, useGlobal, ignoreUndefined) { return new REPLServer(prompt, stream, eval, useGlobal, ignoreUndefined); } + EventEmitter.call(this); + var options, input, output; if (typeof prompt == 'object') { // an options object was given @@ -96,8 +99,6 @@ function REPLServer(prompt, stream, eval, useGlobal, ignoreUndefined) { options = {}; } - EventEmitter.call(this); - var self = this; self.useGlobal = !!useGlobal; @@ -280,6 +281,15 @@ function REPLServer(prompt, stream, eval, useGlobal, ignoreUndefined) { // If error was SyntaxError and not JSON.parse error if (isSyntaxError(e)) { + if (cmd.trim().match(/^npm /) && !self.bufferedCommand) { + self.outputStream.write('npm should be run outside of the ' + + 'node repl, in your normal shell.\n' + + '(Press Control-D to exit.)\n'); + self.bufferedCommand = ''; + self.displayPrompt(); + return; + } + // Start buffering data like that: // { // ... x: 1 @@ -367,6 +377,8 @@ REPLServer.prototype.displayPrompt = function(preserveCursor) { // A stream to push an array into a REPL // used in REPLServer.complete function ArrayStream() { + Stream.call(this); + this.run = function(data) { var self = this; data.forEach(function(line) { @@ -374,7 +386,7 @@ function ArrayStream() { }); } } -util.inherits(ArrayStream, require('stream').Stream); +util.inherits(ArrayStream, Stream); ArrayStream.prototype.readable = true; ArrayStream.prototype.writable = true; ArrayStream.prototype.resume = function() {}; diff --git a/lib/sys.js b/lib/sys.js index 276b0f189ca..cf98a073e6c 100644 --- a/lib/sys.js +++ b/lib/sys.js @@ -1 +1,24 @@ -throw new Error('The "sys" module is now called "util".'); +// Copyright Joyent, Inc. and other Node 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. + +// the sys module was renamed to 'util'. +// this shim remains to keep old programs working. +module.exports = require('util'); diff --git a/lib/tls.js b/lib/tls.js index 439e83e4aff..68e860f0d1d 100644 --- a/lib/tls.js +++ b/lib/tls.js @@ -23,7 +23,7 @@ var crypto = require('crypto'); var util = require('util'); var net = require('net'); var events = require('events'); -var stream = require('stream'); +var Stream = require('stream'); var END_OF_FILE = 42; var assert = require('assert').ok; var constants = require('constants'); @@ -77,9 +77,45 @@ function convertNPNProtocols(NPNProtocols, out) { } } + +function SlabBuffer() { + this.create(); +}; + + +SlabBuffer.prototype.create = function create() { + this.isFull = false; + this.pool = new Buffer(10 * 1024 * 1024); + this.offset = 0; + this.remaining = this.pool.length; +}; + + +SlabBuffer.prototype.use = function use(context, fn) { + if (this.remaining === 0) { + this.isFull = true; + return 0; + } + + var bytes = fn.call(context, this.pool, this.offset, this.remaining); + + if (bytes > 0) { + this.offset += bytes; + this.remaining -= bytes; + } + + assert(this.remaining >= 0); + + return bytes; +}; + + +var slabBuffer = new SlabBuffer(); + + // Base class of both CleartextStream and EncryptedStream function CryptoStream(pair) { - stream.Stream.call(this); + Stream.call(this); this.pair = pair; @@ -90,8 +126,9 @@ function CryptoStream(pair) { this._pending = []; this._pendingCallbacks = []; this._pendingBytes = 0; + this._buffer = slabBuffer; } -util.inherits(CryptoStream, stream.Stream); +util.inherits(CryptoStream, Stream); CryptoStream.prototype.write = function(data /* , encoding, cb */) { @@ -339,18 +376,13 @@ CryptoStream.prototype._push = function() { } while (!this._paused) { - var chunkBytes = 0; - if (!this._pool || (this._poolStart >= this._poolEnd)) { - this._pool = new Buffer(16 * 4096); - this._poolStart = 0; - this._poolEnd = this._pool.length; - } - var start = this._poolStart; + var chunkBytes = 0, + bytesRead = 0, + start = this._buffer.offset; do { - chunkBytes = this._pusher(this._pool, - this._poolStart, - this._poolEnd - this._poolStart); + chunkBytes = this._buffer.use(this, this._pusher); + if (chunkBytes > 0) bytesRead += chunkBytes; if (this.pair.ssl && this.pair.ssl.error) { this.pair.error(); @@ -359,13 +391,12 @@ CryptoStream.prototype._push = function() { this.pair.maybeInitFinished(); - if (chunkBytes >= 0) { - this._poolStart += chunkBytes; - } + } while (chunkBytes > 0 && !this._buffer.isFull); - } while (chunkBytes > 0 && this._poolStart < this._poolEnd); + var pool = this._buffer.pool; - var bytesRead = this._poolStart - start; + // Create new buffer if previous was filled up + if (this._buffer.isFull) this._buffer.create(); assert(bytesRead >= 0); @@ -377,7 +408,7 @@ CryptoStream.prototype._push = function() { return; } - var chunk = this._pool.slice(start, this._poolStart); + var chunk = pool.slice(start, start + bytesRead); if (this === this.pair.cleartext) { debug('cleartext emit "data" with ' + bytesRead + ' bytes'); @@ -393,7 +424,7 @@ CryptoStream.prototype._push = function() { } // Optimization: emit the original buffer with end points - if (this.ondata) this.ondata(this._pool, start, this._poolStart); + if (this.ondata) this.ondata(pool, start, start + bytesRead); } }; @@ -572,16 +603,15 @@ function onhandshakestart() { debug('onhandshakestart'); var self = this, ssl = this.ssl; - ssl.handshakes++; - if (ssl.handshakes === 1) { + if (ssl.timer === null) { function timeout() { ssl.handshakes = 0; ssl.timer = null; } ssl.timer = setTimeout(timeout, exports.CLIENT_RENEG_WINDOW * 1000); } - else if (ssl.handshakes >= exports.CLIENT_RENEG_LIMIT) { + else if (++ssl.handshakes > exports.CLIENT_RENEG_LIMIT) { // Defer the error event to the next tick. We're being called from OpenSSL's // state machine and OpenSSL is not re-entrant. We cannot allow the user's // callback to destroy the connection right now, it would crash and burn. diff --git a/lib/tty.js b/lib/tty.js index 414eed69861..9fa18fd38c1 100644 --- a/lib/tty.js +++ b/lib/tty.js @@ -24,6 +24,7 @@ var inherits = require('util').inherits; var net = require('net'); var TTY = process.binding('tty_wrap').TTY; var isTTY = process.binding('tty_wrap').isTTY; +var util = require('util'); exports.isatty = function(fd) { return isTTY(fd); @@ -31,13 +32,12 @@ exports.isatty = function(fd) { // backwards-compat -exports.setRawMode = function(flag) { +exports.setRawMode = util.deprecate(function(flag) { if (!process.stdin.isTTY) { throw new Error('can\'t set raw mode on non-tty'); } process.stdin.setRawMode(flag); -}; -module.deprecate('setRawMode', 'Use `process.stdin.setRawMode()` instead.'); +}, 'tty.setRawMode: Use `process.stdin.setRawMode()` instead.'); function ReadStream(fd) { diff --git a/lib/util.js b/lib/util.js index 50595fd3f7a..65888920c8d 100644 --- a/lib/util.js +++ b/lib/util.js @@ -54,6 +54,31 @@ exports.format = function(f) { }; +// Mark that a method should not be used. +// Returns a modified function which warns once by default. +// If --no-deprecation is set, then it is a no-op. +exports.deprecate = function(fn, msg) { + if (process.noDeprecation === true) { + return fn; + } + + var warned = false; + function deprecated() { + if (!warned) { + if (process.traceDeprecation) { + console.trace(msg); + } else { + console.error(msg); + } + warned = true; + } + return fn.apply(this, arguments); + } + + return deprecated; +}; + + exports.print = function() { for (var i = 0, len = arguments.length; i < len; ++i) { process.stdout.write(String(arguments[i])); @@ -150,6 +175,17 @@ function stylizeNoColor(str, styleType) { } +function arrayToHash(array) { + var hash = {}; + + array.forEach(function(val, idx) { + hash[val] = true; + }); + + return hash; +} + + function formatValue(ctx, value, recurseTimes) { // Provide a hook for user-specified inspect functions. // Check that value is an object with an inspect function on it @@ -168,8 +204,12 @@ function formatValue(ctx, value, recurseTimes) { } // Look up the keys of the object. - var visibleKeys = Object.keys(value); - var keys = ctx.showHidden ? Object.getOwnPropertyNames(value) : visibleKeys; + var keys = Object.keys(value); + var visibleKeys = arrayToHash(keys); + + if (ctx.showHidden) { + keys = Object.getOwnPropertyNames(value); + } // Some type of object without properties can be shortcutted. if (keys.length === 0) { @@ -309,7 +349,7 @@ function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) { str = ctx.stylize('[Setter]', 'special'); } } - if (visibleKeys.indexOf(key) < 0) { + if (!visibleKeys.hasOwnProperty(key)) { name = '[' + key + ']'; } if (!str) { @@ -407,12 +447,11 @@ function objectToString(o) { } -exports.p = function() { +exports.p = exports.deprecate(function() { for (var i = 0, len = arguments.length; i < len; ++i) { error(exports.inspect(arguments[i])); } -}; -module.deprecate('p', 'Use `util.puts(util.inspect())` instead.'); +}, 'util.p: Use console.error() instead.'); function pad(n) { @@ -438,10 +477,9 @@ exports.log = function(msg) { }; -exports.exec = function() { +exports.exec = exports.deprecate(function() { return require('child_process').exec.apply(this, arguments); -}; -module.deprecate('exec', 'It is now called `child_process.exec`.'); +}, 'util.exec is now called `child_process.exec`.'); exports.pump = function(readStream, writeStream, callback) { diff --git a/lib/zlib.js b/lib/zlib.js index 9b453ea18db..f05f6d1399d 100644 --- a/lib/zlib.js +++ b/lib/zlib.js @@ -21,7 +21,7 @@ var binding = process.binding('zlib'); var util = require('util'); -var stream = require('stream'); +var Stream = require('stream'); var assert = require('assert').ok; // zlib doesn't provide these, so kludge them in following the same @@ -150,25 +150,7 @@ function zlibBuffer(engine, buffer, callback) { } function onEnd() { - var buffer; - switch (buffers.length) { - case 0: - buffer = new Buffer(0); - break; - case 1: - buffer = buffers[0]; - break; - default: - buffer = new Buffer(nread); - var n = 0; - buffers.forEach(function(b) { - var l = b.length; - b.copy(buffer, n, 0, l); - n += l; - }); - break; - } - callback(null, buffer); + callback(null, Buffer.concat(buffers, nread)); } engine.on('error', onError); @@ -233,6 +215,8 @@ function Unzip(opts) { // you call the .write() method. function Zlib(opts, mode) { + Stream.call(this); + this._opts = opts = opts || {}; this._queue = []; this._processing = false; @@ -314,7 +298,7 @@ function Zlib(opts, mode) { var self = this; } -util.inherits(Zlib, stream.Stream); +util.inherits(Zlib, Stream); Zlib.prototype.write = function write(chunk, cb) { if (this._hadError) return true; diff --git a/node.gyp b/node.gyp index 0aacc5fb049..933812e3dfa 100644 --- a/node.gyp +++ b/node.gyp @@ -5,10 +5,11 @@ # See http://codereview.chromium.org/8159015 'werror': '', 'node_use_dtrace%': 'false', + 'node_use_etw%': 'false', 'node_shared_v8%': 'false', 'node_shared_zlib%': 'false', 'node_use_openssl%': 'true', - 'node_use_system_openssl%': 'false', + 'node_shared_openssl%': 'false', 'library_files': [ 'src/node.js', 'lib/_debugger.js', @@ -81,6 +82,7 @@ 'src/node_main.cc', 'src/node_os.cc', 'src/node_script.cc', + 'src/node_stat_watcher.cc', 'src/node_string.cc', 'src/node_zlib.cc', 'src/pipe_wrap.cc', @@ -135,7 +137,7 @@ 'defines': [ 'HAVE_OPENSSL=1' ], 'sources': [ 'src/node_crypto.cc' ], 'conditions': [ - [ 'node_use_system_openssl=="false"', { + [ 'node_shared_openssl=="false"', { 'dependencies': [ './deps/openssl/openssl.gyp:openssl' ], }]] }, { @@ -163,13 +165,19 @@ } ] ], } ], - - [ 'node_shared_v8=="true"', { + [ 'node_use_etw=="true"', { + 'defines': [ 'HAVE_ETW=1' ], + 'dependencies': [ 'node_etw' ], 'sources': [ - '<(node_shared_v8_includes)/v8.h', - '<(node_shared_v8_includes)/v8-debug.h', - ], - }, { + 'src/node_win32_etw_provider.h', + 'src/node_win32_etw_provider-inl.h', + 'src/node_win32_etw_provider.cc', + 'src/node_dtrace.cc', + '<(SHARED_INTERMEDIATE_DIR)/node_etw_provider.h', + '<(SHARED_INTERMEDIATE_DIR)/node_etw_provider.rc', + ] + } ], + [ 'node_shared_v8=="false"', { 'sources': [ 'deps/v8/include/v8.h', 'deps/v8/include/v8-debug.h', @@ -183,7 +191,7 @@ [ 'OS=="win"', { 'sources': [ - 'tools/msvs/res/node.rc', + 'src/res/node.rc', ], 'defines': [ 'FD_SETSIZE=1024', @@ -196,7 +204,6 @@ 'defines': [ '__POSIX__' ], 'sources': [ 'src/node_signal_watcher.cc', - 'src/node_stat_watcher.cc', 'src/node_io_watcher.cc', ] }], @@ -228,7 +235,23 @@ }, }, }, - + # generate ETW header and resource files + { + 'target_name': 'node_etw', + 'type': 'none', + 'conditions': [ + [ 'node_use_etw=="true"', { + 'actions': [ + { + 'action_name': 'node_etw', + 'inputs': [ 'src/res/node_etw_provider.man' ], + 'outputs': [ '<(SHARED_INTERMEDIATE_DIR)' ], + 'action': [ 'mc <@(_inputs) -h <@(_outputs) -r <@(_outputs)' ] + } + ] + } ] + ] + }, { 'target_name': 'node_js2c', 'type': 'none', @@ -251,7 +274,7 @@ # action? 'conditions': [ - [ 'node_use_dtrace=="true"', { + [ 'node_use_dtrace=="true" or node_use_etw=="true"', { 'action': [ 'python', 'tools/js2c.py', diff --git a/src/eio-emul.h b/src/eio-emul.h new file mode 100644 index 00000000000..03fc5dfccdf --- /dev/null +++ b/src/eio-emul.h @@ -0,0 +1,71 @@ +/* Copyright Joyent, Inc. and other Node 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. + */ + +#ifndef NODE_EIO_EMUL_H_ +#define NODE_EIO_EMUL_H_ + +#define eio_nop(a,b,c) eio_nop(a,b,c,(&uv_default_loop()->uv_eio_channel)) +#define eio_busy(a,b,c,d) eio_busy(a,b,c,d,(&uv_default_loop()->uv_eio_channel)) +#define eio_sync(a,b,c) eio_sync(a,b,c,(&uv_default_loop()->uv_eio_channel)) +#define eio_fsync(a,b,c,d) eio_fsync(a,b,c,d,(&uv_default_loop()->uv_eio_channel)) +#define eio_msync(a,b,c,d,e,f) eio_msync(a,b,c,d,e,f,(&uv_default_loop()->uv_eio_channel)) +#define eio_fdatasync(a,b,c,d) eio_fdatasync(a,b,c,d,(&uv_default_loop()->uv_eio_channel)) +#define eio_syncfs(a,b,c,d) eio_syncfs(a,b,c,d,(&uv_default_loop()->uv_eio_channel)) +#define eio_sync_file_range(a,b,c,d,e,f,g) eio_sync_file_range(a,b,c,d,e,f,g,(&uv_default_loop()->uv_eio_channel)) +#define eio_mtouch(a,b,c,d,e,f) eio_mtouch(a,b,c,d,e,f,(&uv_default_loop()->uv_eio_channel)) +#define eio_mlock(a,b,c,d,e) eio_mlock(a,b,c,d,e,(&uv_default_loop()->uv_eio_channel)) +#define eio_mlockall(a,b,c,d) eio_mlockall(a,b,c,d,(&uv_default_loop()->uv_eio_channel)) +#define eio_fallocate(a,b,c,d,e,f,g) eio_fallocate(a,b,c,d,e,f,g,(&uv_default_loop()->uv_eio_channel)) +#define eio_close(a,b,c,d) eio_close(a,b,c,d,(&uv_default_loop()->uv_eio_channel)) +#define eio_readahead(a,b,c,d,e,f) eio_readahead(a,b,c,d,e,f,(&uv_default_loop()->uv_eio_channel)) +#define eio_read(a,b,c,d,e,f,g) eio_read(a,b,c,d,e,f,g,(&uv_default_loop()->uv_eio_channel)) +#define eio_write(a,b,c,d,e,f,g) eio_write(a,b,c,d,e,f,g,(&uv_default_loop()->uv_eio_channel)) +#define eio_fstat(a,b,c,d) eio_fstat(a,b,c,d,(&uv_default_loop()->uv_eio_channel)) +#define eio_fstatvfs(a,b,c,d) eio_fstatvfs(a,b,c,d,(&uv_default_loop()->uv_eio_channel)) +#define eio_futime(a,b,c,d,e,f) eio_futime(a,b,c,d,e,f,(&uv_default_loop()->uv_eio_channel)) +#define eio_ftruncate(a,b,c,d,e) eio_ftruncate(a,b,c,d,e,(&uv_default_loop()->uv_eio_channel)) +#define eio_fchmod(a,b,c,d,e) eio_fchmod(a,b,c,d,e,(&uv_default_loop()->uv_eio_channel)) +#define eio_fchown(a,b,c,d,e,f) eio_fchown(a,b,c,d,e,f,(&uv_default_loop()->uv_eio_channel)) +#define eio_dup2(a,b,c,d,e) eio_dup2(a,b,c,d,e,(&uv_default_loop()->uv_eio_channel)) +#define eio_sendfile(a,b,c,d,e,f,g) eio_sendfile(a,b,c,d,e,f,g,(&uv_default_loop()->uv_eio_channel)) +#define eio_open(a,b,c,d,e,f) eio_open(a,b,c,d,e,f,(&uv_default_loop()->uv_eio_channel)) +#define eio_utime(a,b,c,d,e,f) eio_utime(a,b,c,d,e,f,(&uv_default_loop()->uv_eio_channel)) +#define eio_truncate(a,b,c,d,e) eio_truncate(a,b,c,d,e,(&uv_default_loop()->uv_eio_channel)) +#define eio_chown(a,b,c,d,e,f) eio_chown(a,b,c,d,e,f,(&uv_default_loop()->uv_eio_channel)) +#define eio_chmod(a,b,c,d,e) eio_chmod(a,b,c,d,e,(&uv_default_loop()->uv_eio_channel)) +#define eio_mkdir(a,b,c,d,e) eio_mkdir(a,b,c,d,e,(&uv_default_loop()->uv_eio_channel)) +#define eio_readlink(a,b,c,d) eio_readlink(a,b,c,d,(&uv_default_loop()->uv_eio_channel)) +#define eio_realpath(a,b,c,d) eio_realpath(a,b,c,d,(&uv_default_loop()->uv_eio_channel)) +#define eio_stat(a,b,c,d) eio_stat(a,b,c,d,(&uv_default_loop()->uv_eio_channel)) +#define eio_lstat(a,b,c,d) eio_lstat(a,b,c,d,(&uv_default_loop()->uv_eio_channel)) +#define eio_statvfs(a,b,c,d) eio_statvfs(a,b,c,d,(&uv_default_loop()->uv_eio_channel)) +#define eio_unlink(a,b,c,d) eio_unlink(a,b,c,d,(&uv_default_loop()->uv_eio_channel)) +#define eio_rmdir(a,b,c,d) eio_rmdir(a,b,c,d,(&uv_default_loop()->uv_eio_channel)) +#define eio_readdir(a,b,c,d,e) eio_readdir(a,b,c,d,e,(&uv_default_loop()->uv_eio_channel)) +#define eio_mknod(a,b,c,d,e,f) eio_mknod(a,b,c,d,e,f,(&uv_default_loop()->uv_eio_channel)) +#define eio_link(a,b,c,d,e) eio_link(a,b,c,d,e,(&uv_default_loop()->uv_eio_channel)) +#define eio_symlink(a,b,c,d,e) eio_symlink(a,b,c,d,e,(&uv_default_loop()->uv_eio_channel)) +#define eio_rename(a,b,c,d,e) eio_rename(a,b,c,d,e,(&uv_default_loop()->uv_eio_channel)) +#define eio_custom(a,b,c,d) eio_custom((void (*)(eio_req*))a,b,c,d,(&uv_default_loop()->uv_eio_channel)) +#define eio_grp(a,b) eio_grp(a,b,(&uv_default_loop()->uv_eio_channel)) + +#endif /* NODE_EIO_EMUL_H_ */ diff --git a/src/ev-emul.h b/src/ev-emul.h new file mode 100644 index 00000000000..cf924c744e3 --- /dev/null +++ b/src/ev-emul.h @@ -0,0 +1,259 @@ +/* Copyright Joyent, Inc. and other Node 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. + */ + +#ifndef NODE_EV_EMUL_H_ +#define NODE_EV_EMUL_H_ + +#include "uv.h" + +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#undef ev_init +#undef ev_set_cb +#undef ev_set_priority +#undef ev_is_active +#undef ev_timer_init +#undef ev_timer_set +#undef ev_io_init +#undef ev_io_set + +#undef EV_P +#undef EV_P_ +#undef EV_A +#undef EV_A_ +#undef EV_DEFAULT +#undef EV_DEFAULT_ +#undef EV_DEFAULT_UC +#undef EV_DEFAULT_UC_ + +#define EV_P void +#define EV_P_ +#define EV_A +#define EV_A_ +#define EV_DEFAULT +#define EV_DEFAULT_ +#define EV_DEFAULT_UC +#define EV_DEFAULT_UC_ + +#define ev_init(w, cb_) \ + do { \ + void* data = (w)->data; \ + memset((w), 0, sizeof(*(w))); \ + (w)->data = data; \ + (w)->cb = (cb_); \ + } \ + while (0) + +#define ev_set_cb(w, cb_) \ + do \ + (w)->cb = (cb_); \ + while (0) + +#define ev_set_priority(...) + +#define ev_is_active(w) \ + (uv_is_active((uv_handle_t*) &(w)->handle)) + +#define ev_now(...) \ + (uv_hrtime() / 1e9) + +#define __uv_container_of(ptr, type, field) \ + ((type*) ((char*) (ptr) - offsetof(type, field))) + +#define __uv_warn_of(old_, new_) \ + do { \ + if (__uv_warn_##old_ || node::no_deprecation) break; \ + __uv_warn_##old_ = 1; \ + fputs("WARNING: " #old_ " is deprecated, use " #new_ "\n", stderr); \ + } \ + while (0) + +static int __uv_warn_ev_io __attribute__((unused)); +static int __uv_warn_ev_timer __attribute__((unused)); +static int __uv_warn_ev_ref __attribute__((unused)); +static int __uv_warn_ev_unref __attribute__((unused)); + +struct __ev_io; +typedef struct __ev_io __ev_io; +typedef void (*__ev_io_cb)(__ev_io*, int); + +struct __ev_timer; +typedef struct __ev_timer __ev_timer; +typedef void (*__ev_timer_cb)(__ev_timer*, int); + +/* Field order matters. Don't touch. */ +struct __ev_io { + __ev_io_cb cb; + void* data; + int flags; /* bit 1 == initialized, yes or no? */ + uv_poll_t handle; + int fd; + int events; +}; + +/* Field order matters. Don't touch. */ +struct __ev_timer { + __ev_timer_cb cb; + void* data; + int flags; + uv_timer_t handle; + double delay; + double repeat; +}; + + +inline static void __uv_poll_cb(uv_poll_t* handle, int status, int events) { + __ev_io* w = __uv_container_of(handle, __ev_io, handle); + w->cb(w, events); + (void) status; +} + + +inline static void __uv_timer_cb(uv_timer_t* handle, int status) { + __ev_timer* w = __uv_container_of(handle, __ev_timer, handle); + w->cb(w, 0); + (void) status; +} + + +inline static void __ev_io_init(__ev_io* w, __ev_io_cb cb, int fd, int events) { + __uv_warn_of(ev_io, uv_poll_t); + ev_init(w, cb); + w->fd = fd; + w->events = events; +} + + +inline static void __ev_io_set(__ev_io* w, int fd, int events) { + __uv_warn_of(ev_io, uv_poll_t); + w->fd = fd; + w->events = events; +} + + +inline static void __ev_io_start(__ev_io* w) { + __uv_warn_of(ev_io, uv_poll_t); + if (!(w->flags & 1)) { + uv_poll_init(uv_default_loop(), &w->handle, w->fd); + w->flags |= 1; + } + uv_poll_start(&w->handle, w->events, __uv_poll_cb); +} + + +inline static void __ev_io_stop(__ev_io* w) { + __uv_warn_of(ev_io, uv_poll_t); + uv_poll_stop(&w->handle); +} + + +inline static void __ev_timer_init(__ev_timer* w, + __ev_timer_cb cb, + double delay, + double repeat) { + __uv_warn_of(ev_timer, uv_timer_t); + ev_init(w, cb); + w->delay = delay; + w->repeat = repeat; +} + + +inline static void __ev_timer_set(__ev_timer* w, + double delay, + double repeat) { + __uv_warn_of(ev_timer, uv_timer_t); + w->delay = delay; + w->repeat = repeat; +} + + +inline static void __ev_timer_start(__ev_timer* w) { + uint64_t ms = 1000; + __uv_warn_of(ev_timer, uv_timer_t); + if (!(w->flags & 1)) { + uv_timer_init(uv_default_loop(), &w->handle); + w->flags |= 1; + } + uv_timer_start(&w->handle, __uv_timer_cb, w->delay * ms, w->repeat * ms); +} + + +inline static void __ev_timer_stop(__ev_timer* w) { + __uv_warn_of(ev_timer, uv_timer_t); + uv_timer_stop(&w->handle); +} + + +inline static void __ev_timer_again(__ev_timer* w) { + __uv_warn_of(ev_timer, uv_timer_t); + if (w->flags & 1) + uv_timer_again(&w->handle); + else + __ev_timer_start(w); /* work around node-zookeeper bug */ +} + + +/* Evil. Using this will void your warranty. */ +inline static void __ev_ref(void) { + __uv_warn_of(ev_ref, uv_ref); + uv_default_loop()->active_handles++; +} + + +/* Evil. Using this will void your warranty. */ +inline static void __ev_unref(void) { + __uv_warn_of(ev_unref, uv_unref); + uv_default_loop()->active_handles--; +} + + +#define ev_io __ev_io +#define ev_io_init __ev_io_init +#define ev_io_set __ev_io_set +#define ev_io_start __ev_io_start +#define ev_io_stop __ev_io_stop + +#define ev_timer __ev_timer +#define ev_timer_init __ev_timer_init +#define ev_timer_set __ev_timer_set +#define ev_timer_start __ev_timer_start +#define ev_timer_stop __ev_timer_stop +#define ev_timer_again __ev_timer_again + +#define ev_ref __ev_ref +#define ev_unref __ev_unref + +#undef __uv_container_of +#undef __uv_warn_of + +#ifdef __cplusplus +} +#endif + +#endif /* NODE_EV_EMUL_H_ */ diff --git a/src/handle_wrap.cc b/src/handle_wrap.cc index 944631a3be6..ead7da1f747 100644 --- a/src/handle_wrap.cc +++ b/src/handle_wrap.cc @@ -50,8 +50,18 @@ void HandleWrap::Initialize(Handle target) { } -// This function is used only for process.stdout. It's put here instead of -// in TTYWrap because here we have access to the Close binding. +Handle HandleWrap::Ref(const Arguments& args) { + HandleScope scope; + + UNWRAP(HandleWrap) + + uv_ref(wrap->handle__); + wrap->unref_ = false; + + return v8::Undefined(); +} + + Handle HandleWrap::Unref(const Arguments& args) { HandleScope scope; diff --git a/src/handle_wrap.h b/src/handle_wrap.h index 35853a01105..a358e812a50 100644 --- a/src/handle_wrap.h +++ b/src/handle_wrap.h @@ -50,6 +50,7 @@ class HandleWrap { public: static void Initialize(v8::Handle target); static v8::Handle Close(const v8::Arguments& args); + static v8::Handle Ref(const v8::Arguments& args); static v8::Handle Unref(const v8::Arguments& args); protected: diff --git a/src/node.cc b/src/node.cc index 5db4d86c287..cdcd1c92736 100644 --- a/src/node.cc +++ b/src/node.cc @@ -26,7 +26,7 @@ #include "uv.h" #include "v8-debug.h" -#ifdef HAVE_DTRACE +#if defined HAVE_DTRACE || defined HAVE_ETW # include "node_dtrace.h" #endif @@ -69,7 +69,6 @@ typedef int mode_t; #include "node_http_parser.h" #ifdef __POSIX__ # include "node_signal_watcher.h" -# include "node_stat_watcher.h" #endif #include "node_constants.h" #include "node_javascript.h" @@ -121,6 +120,7 @@ static Persistent disposed_symbol; static bool print_eval = false; static bool force_repl = false; +static bool trace_deprecation = false; static char *eval_string = NULL; static int option_end_index = 0; static bool use_debug_agent = false; @@ -128,6 +128,9 @@ static bool debug_wait_connect = false; static int debug_port=5858; static int max_stack_size = 0; +// used by C++ modules as well +bool no_deprecation = false; + static uv_check_t check_tick_watcher; static uv_prepare_t prepare_tick_watcher; static uv_idle_t tick_spinner; @@ -1095,12 +1098,16 @@ enum encoding ParseEncoding(Handle encoding_v, enum encoding _default) { } else if (strcasecmp(*encoding, "hex") == 0) { return HEX; } else if (strcasecmp(*encoding, "raw") == 0) { - fprintf(stderr, "'raw' (array of integers) has been removed. " - "Use 'binary'.\n"); + if (!no_deprecation) { + fprintf(stderr, "'raw' (array of integers) has been removed. " + "Use 'binary'.\n"); + } return BINARY; } else if (strcasecmp(*encoding, "raws") == 0) { - fprintf(stderr, "'raws' encoding has been renamed to 'binary'. " - "Please update your code.\n"); + if (!no_deprecation) { + fprintf(stderr, "'raws' encoding has been renamed to 'binary'. " + "Please update your code.\n"); + } return BINARY; } else { return _default; @@ -1952,8 +1959,8 @@ static Handle EnvGetter(Local property, return scope.Close(String::New(reinterpret_cast(buffer), result)); } #endif - // Not found - return Undefined(); + // Not found. Fetch from prototype. + return scope.Close(info.Data().As()->Get(property)); } @@ -2123,8 +2130,9 @@ Handle SetupProcessObject(int argc, char *argv[]) { Local process_template = FunctionTemplate::New(); - process = Persistent::New(process_template->GetFunction()->NewInstance()); + process_template->SetClassName(String::NewSymbol("process")); + process = Persistent::New(process_template->GetFunction()->NewInstance()); process->SetAccessor(String::New("title"), ProcessTitleGetter, @@ -2133,11 +2141,6 @@ Handle SetupProcessObject(int argc, char *argv[]) { // process.version process->Set(String::NewSymbol("version"), String::New(NODE_VERSION)); -#ifdef NODE_PREFIX - // process.installPrefix - process->Set(String::NewSymbol("installPrefix"), String::New(NODE_PREFIX)); -#endif - // process.moduleLoadList module_load_list = Persistent::New(Array::New()); process->Set(String::NewSymbol("moduleLoadList"), module_load_list); @@ -2207,7 +2210,7 @@ Handle SetupProcessObject(int argc, char *argv[]) { EnvQuery, EnvDeleter, EnvEnumerator, - Undefined()); + Object::New()); Local env = envTemplate->NewInstance(); process->Set(String::NewSymbol("env"), env); @@ -2229,6 +2232,16 @@ Handle SetupProcessObject(int argc, char *argv[]) { process->Set(String::NewSymbol("_forceRepl"), True()); } + // --no-deprecation + if (no_deprecation) { + process->Set(String::NewSymbol("noDeprecation"), True()); + } + + // --trace-deprecation + if (trace_deprecation) { + process->Set(String::NewSymbol("traceDeprecation"), True()); + } + size_t size = 2*PATH_MAX; char* execPath = new char[size]; if (uv_exepath(execPath, &size) != 0) { @@ -2325,7 +2338,7 @@ void Load(Handle process_l) { Local global = v8::Context::GetCurrent()->Global(); Local args[1] = { Local::New(process_l) }; -#ifdef HAVE_DTRACE +#if defined HAVE_DTRACE || defined HAVE_ETW InitDTrace(global); #endif @@ -2376,8 +2389,9 @@ static void PrintHelp() { " -p, --print print result of --eval\n" " -i, --interactive always enter the REPL even if stdin\n" " does not appear to be a terminal\n" + " --no-deprecation silence deprecation warnings\n" + " --trace-deprecation show stack traces on deprecations\n" " --v8-options print v8 command line options\n" - " --vars print various compiled-in variables\n" " --max-stack-size=val set max v8 stack size (bytes)\n" "\n" "Environment variables:\n" @@ -2407,14 +2421,6 @@ static void ParseArgs(int argc, char **argv) { } else if (strcmp(arg, "--version") == 0 || strcmp(arg, "-v") == 0) { printf("%s\n", NODE_VERSION); exit(0); - } else if (strcmp(arg, "--vars") == 0) { -#ifdef NODE_PREFIX - printf("NODE_PREFIX: %s\n", NODE_PREFIX); -#endif -#ifdef NODE_CFLAGS - printf("NODE_CFLAGS: %s\n", NODE_CFLAGS); -#endif - exit(0); } else if (strstr(arg, "--max-stack-size=") == arg) { const char *p = 0; p = 1 + strchr(arg, '='); @@ -2442,6 +2448,12 @@ static void ParseArgs(int argc, char **argv) { argv[i] = const_cast(""); } else if (strcmp(arg, "--v8-options") == 0) { argv[i] = const_cast("--help"); + } else if (strcmp(arg, "--no-deprecation") == 0) { + argv[i] = const_cast(""); + no_deprecation = true; + } else if (strcmp(arg, "--trace-deprecation") == 0) { + argv[i] = const_cast(""); + trace_deprecation = true; } else if (argv[i][0] != '-') { break; } @@ -2698,6 +2710,9 @@ char** Init(int argc, char *argv[]) { // Initialize prog_start_time to get relative uptime. uv_uptime(&prog_start_time); + // Make inherited handles noninheritable. + uv_disable_stdio_inheritance(); + // Parse a few arguments which are specific to Node. node::ParseArgs(argc, argv); // Parse the rest of the args (up to the 'option_end_index' (where '--' was diff --git a/src/node.h b/src/node.h index aed1078b21b..2e443507153 100644 --- a/src/node.h +++ b/src/node.h @@ -85,7 +85,9 @@ namespace node { -int Start(int argc, char *argv[]); +NODE_EXTERN extern bool no_deprecation; + +NODE_EXTERN int Start(int argc, char *argv[]); char** Init(int argc, char *argv[]); v8::Handle SetupProcessObject(int argc, char *argv[]); @@ -144,19 +146,7 @@ ssize_t DecodeWrite(char *buf, v8::Handle, enum encoding encoding = BINARY); -// Use different stat structs & calls on windows and posix; -// on windows, _stati64 is utf-8 and big file aware. -#if __POSIX__ -# define NODE_STAT stat -# define NODE_FSTAT fstat -# define NODE_STAT_STRUCT struct stat -#else // _WIN32 -# define NODE_STAT _stati64 -# define NODE_FSTAT _fstati64 -# define NODE_STAT_STRUCT struct _stati64 -#endif - -v8::Local BuildStatsObject(NODE_STAT_STRUCT *s); +v8::Local BuildStatsObject(const uv_statbuf_t* s); /** @@ -273,5 +263,12 @@ MakeCallback(const v8::Handle object, const v8::Handle callback, int argc, v8::Handle argv[]); + } // namespace node + +#if !defined(NODE_WANT_INTERNALS) && !defined(_WIN32) +# include "ev-emul.h" +# include "eio-emul.h" +#endif + #endif // SRC_NODE_H_ diff --git a/src/node.js b/src/node.js index ba0786d6ea2..e3e1f7d3c8f 100644 --- a/src/node.js +++ b/src/node.js @@ -29,7 +29,13 @@ function startup() { var EventEmitter = NativeModule.require('events').EventEmitter; - process.__proto__ = EventEmitter.prototype; + + process.__proto__ = Object.create(EventEmitter.prototype, { + constructor: { + value: process.constructor + } + }); + process.EventEmitter = EventEmitter; // process.EventEmitter is deprecated startup.globalVariables(); @@ -394,6 +400,14 @@ // know yet. Call pause() explicitly to unref() it. stdin.pause(); + // when piping stdin to a destination stream, + // let the data begin to flow. + var pipe = stdin.pipe; + stdin.pipe = function(dest, opts) { + stdin.resume(); + return pipe.call(stdin, dest, opts); + }; + return stdin; }); @@ -430,6 +444,8 @@ if (r) { throw errnoException(errno, 'kill'); } + + return true; }; }; @@ -592,34 +608,5 @@ NativeModule._cache[this.id] = this; }; - // Wrap a core module's method in a wrapper that will warn on first use - // and then return the result of invoking the original function. After - // first being called the original method is restored. - NativeModule.prototype.deprecate = function(method, message) { - var original = this.exports[method]; - var self = this; - var warned = false; - message = message || ''; - - Object.defineProperty(this.exports, method, { - enumerable: false, - value: function() { - if (!warned) { - warned = true; - message = self.id + '.' + method + ' is deprecated. ' + message; - - var moduleIdCheck = new RegExp('\\b' + self.id + '\\b'); - if (moduleIdCheck.test(process.env.NODE_DEBUG)) - console.trace(message); - else - console.error(message); - - self.exports[method] = original; - } - return original.apply(this, arguments); - } - }); - }; - startup(); }); diff --git a/src/node_config.h.in b/src/node_config.h.in deleted file mode 100644 index 18d1d7504ae..00000000000 --- a/src/node_config.h.in +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright Joyent, Inc. and other Node 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. - -#ifndef NODE_CONFIG_H -#define NODE_CONFIG_H - -#define NODE_CFLAGS "@CCFLAGS@ @CPPFLAGS@ -I@PREFIX@/include/node" -#define NODE_PREFIX "@PREFIX@" - -#endif /* NODE_CONFIG_H */ diff --git a/src/node_crypto.cc b/src/node_crypto.cc index 14269d5507e..b09fbbb1dc2 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -297,7 +297,14 @@ Handle SecureContext::SetKey(const Arguments& args) { if (!key) { BIO_free(bio); - return False(); + unsigned long err = ERR_get_error(); + if (!err) { + return ThrowException(Exception::Error( + String::New("PEM_read_bio_PrivateKey"))); + } + char string[120]; + ERR_error_string_n(err, string, sizeof string); + return ThrowException(Exception::Error(String::New(string))); } SSL_CTX_use_PrivateKey(sc->ctx_, key); @@ -2083,9 +2090,12 @@ class Cipher : public ObjectWrap { Cipher *cipher = ObjectWrap::Unwrap(args.This()); - cipher->incomplete_base64=NULL; + cipher->incomplete_base64 = NULL; - if (args.Length() <= 1 || !args[0]->IsString() || !args[1]->IsString()) { + if (args.Length() <= 1 + || !args[0]->IsString() + || !(args[1]->IsString() || Buffer::HasInstance(args[1]))) + { return ThrowException(Exception::Error(String::New( "Must give cipher-type, key"))); } @@ -2121,9 +2131,13 @@ class Cipher : public ObjectWrap { HandleScope scope; - cipher->incomplete_base64=NULL; + cipher->incomplete_base64 = NULL; - if (args.Length() <= 2 || !args[0]->IsString() || !args[1]->IsString() || !args[2]->IsString()) { + if (args.Length() <= 2 + || !args[0]->IsString() + || !(args[1]->IsString() || Buffer::HasInstance(args[1])) + || !(args[2]->IsString() || Buffer::HasInstance(args[2]))) + { return ThrowException(Exception::Error(String::New( "Must give cipher-type, key, and iv as argument"))); } @@ -2495,10 +2509,13 @@ class Decipher : public ObjectWrap { HandleScope scope; - cipher->incomplete_utf8=NULL; - cipher->incomplete_hex_flag=false; + cipher->incomplete_utf8 = NULL; + cipher->incomplete_hex_flag = false; - if (args.Length() <= 1 || !args[0]->IsString() || !args[1]->IsString()) { + if (args.Length() <= 1 + || !args[0]->IsString() + || !(args[1]->IsString() || Buffer::HasInstance(args[1]))) + { return ThrowException(Exception::Error(String::New( "Must give cipher-type, key as argument"))); } @@ -2533,10 +2550,14 @@ class Decipher : public ObjectWrap { HandleScope scope; - cipher->incomplete_utf8=NULL; - cipher->incomplete_hex_flag=false; + cipher->incomplete_utf8 = NULL; + cipher->incomplete_hex_flag = false; - if (args.Length() <= 2 || !args[0]->IsString() || !args[1]->IsString() || !args[2]->IsString()) { + if (args.Length() <= 2 + || !args[0]->IsString() + || !(args[1]->IsString() || Buffer::HasInstance(args[1])) + || !(args[2]->IsString() || Buffer::HasInstance(args[2]))) + { return ThrowException(Exception::Error(String::New( "Must give cipher-type, key, and iv as argument"))); } @@ -3945,6 +3966,15 @@ class DiffieHellman : public ObjectWrap { Local outString; + // DH_size returns number of bytes in a prime number + // DH_compute_key returns number of bytes in a remainder of exponent, which + // may have less bytes than a prime number. Therefore add 0-padding to the + // allocated buffer. + if (size != dataSize) { + assert(dataSize > size); + memset(data + size, 0, dataSize - size); + } + if (size == -1) { int checkResult; if (!DH_check_pub_key(diffieHellman->dh, key, &checkResult)) { diff --git a/src/node_dtrace.cc b/src/node_dtrace.cc index 01ea7b87fd9..e560999c52f 100644 --- a/src/node_dtrace.cc +++ b/src/node_dtrace.cc @@ -24,6 +24,9 @@ #ifdef HAVE_DTRACE #include "node_provider.h" +#elif HAVE_ETW +#include "node_win32_etw_provider.h" +#include "node_win32_etw_provider-inl.h" #else #define NODE_HTTP_SERVER_REQUEST(arg0, arg1) #define NODE_HTTP_SERVER_REQUEST_ENABLED() (0) @@ -315,7 +318,11 @@ void InitDTrace(Handle target) { target->Set(String::NewSymbol(tab[i].name), tab[i].templ->GetFunction()); } -#ifdef HAVE_DTRACE +#ifdef HAVE_ETW + init_etw(); +#endif + +#if defined HAVE_DTRACE || defined HAVE_ETW v8::V8::AddGCPrologueCallback((GCPrologueCallback)dtrace_gc_start); v8::V8::AddGCEpilogueCallback((GCEpilogueCallback)dtrace_gc_done); #endif diff --git a/src/node_file.cc b/src/node_file.cc index d8f629f3d59..7e8badf5c22 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -22,9 +22,7 @@ #include "node.h" #include "node_file.h" #include "node_buffer.h" -#ifdef __POSIX__ -# include "node_stat_watcher.h" -#endif +#include "node_stat_watcher.h" #include "req_wrap.h" #include @@ -158,10 +156,7 @@ static void After(uv_fs_t *req) { case UV_FS_STAT: case UV_FS_LSTAT: case UV_FS_FSTAT: - { - NODE_STAT_STRUCT *s = reinterpret_cast(req->ptr); - argv[1] = BuildStatsObject(s); - } + argv[1] = BuildStatsObject(static_cast(req->ptr)); break; case UV_FS_READLINK: @@ -284,7 +279,7 @@ static Persistent atime_symbol; static Persistent mtime_symbol; static Persistent ctime_symbol; -Local BuildStatsObject(NODE_STAT_STRUCT *s) { +Local BuildStatsObject(const uv_statbuf_t* s) { HandleScope scope; if (dev_symbol.IsEmpty()) { @@ -362,7 +357,8 @@ static Handle Stat(const Arguments& args) { ASYNC_CALL(stat, args[1], *path) } else { SYNC_CALL(stat, *path, *path) - return scope.Close(BuildStatsObject((NODE_STAT_STRUCT*)SYNC_REQ.ptr)); + return scope.Close( + BuildStatsObject(static_cast(SYNC_REQ.ptr))); } } @@ -378,7 +374,8 @@ static Handle LStat(const Arguments& args) { ASYNC_CALL(lstat, args[1], *path) } else { SYNC_CALL(lstat, *path, *path) - return scope.Close(BuildStatsObject((NODE_STAT_STRUCT*)SYNC_REQ.ptr)); + return scope.Close( + BuildStatsObject(static_cast(SYNC_REQ.ptr))); } } @@ -395,7 +392,8 @@ static Handle FStat(const Arguments& args) { ASYNC_CALL(fstat, args[1], fd) } else { SYNC_CALL(fstat, 0, fd) - return scope.Close(BuildStatsObject((NODE_STAT_STRUCT*)SYNC_REQ.ptr)); + return scope.Close( + BuildStatsObject(static_cast(SYNC_REQ.ptr))); } } @@ -984,9 +982,7 @@ void InitFs(Handle target) { oncomplete_sym = NODE_PSYMBOL("oncomplete"); -#ifdef __POSIX__ StatWatcher::Initialize(target); -#endif } } // end namespace node diff --git a/src/node_io_watcher.cc b/src/node_io_watcher.cc index ad9a7b63fc2..f238d60e2d0 100644 --- a/src/node_io_watcher.cc +++ b/src/node_io_watcher.cc @@ -84,6 +84,10 @@ Handle IOWatcher::New(const Arguments& args) { return FromConstructorTemplate(constructor_template, args); } + if (!no_deprecation) { + fprintf(stderr, "WARNING: don't use IOWatcher, it'll be removed in v0.9\n"); + } + HandleScope scope; IOWatcher *s = new IOWatcher(); s->Wrap(args.This()); diff --git a/src/node_stat_watcher.cc b/src/node_stat_watcher.cc index efe3939e9bb..8f38033d1a2 100644 --- a/src/node_stat_watcher.cc +++ b/src/node_stat_watcher.cc @@ -33,6 +33,7 @@ Persistent StatWatcher::constructor_template; static Persistent onchange_sym; static Persistent onstop_sym; + void StatWatcher::Initialize(Handle target) { HandleScope scope; @@ -48,61 +49,48 @@ void StatWatcher::Initialize(Handle target) { } -void StatWatcher::Callback(EV_P_ ev_stat *watcher, int revents) { - assert(revents == EV_STAT); - StatWatcher *handler = static_cast(watcher->data); - assert(watcher == &handler->watcher_); +void StatWatcher::Callback(uv_fs_poll_t* handle, + int status, + const uv_statbuf_t* prev, + const uv_statbuf_t* curr) { + StatWatcher* wrap = container_of(handle, StatWatcher, watcher_); + assert(handle == &wrap->watcher_); HandleScope scope; - Local argv[2]; - argv[0] = BuildStatsObject(&watcher->attr); - argv[1] = BuildStatsObject(&watcher->prev); + Local argv[3]; + argv[0] = BuildStatsObject(curr); + argv[1] = BuildStatsObject(prev); + argv[2] = Integer::New(status); + if (status == -1) { + SetErrno(uv_last_error(wrap->watcher_.loop)); + } if (onchange_sym.IsEmpty()) { onchange_sym = NODE_PSYMBOL("onchange"); } - MakeCallback(handler->handle_, onchange_sym, ARRAY_SIZE(argv), argv); + MakeCallback(wrap->handle_, onchange_sym, ARRAY_SIZE(argv), argv); } Handle StatWatcher::New(const Arguments& args) { - if (!args.IsConstructCall()) { - return FromConstructorTemplate(constructor_template, args); - } - + assert(args.IsConstructCall()); HandleScope scope; - StatWatcher *s = new StatWatcher(); + StatWatcher* s = new StatWatcher(); s->Wrap(args.Holder()); return args.This(); } Handle StatWatcher::Start(const Arguments& args) { + assert(args.Length() == 3); HandleScope scope; - if (args.Length() < 1 || !args[0]->IsString()) { - return ThrowException(Exception::TypeError(String::New("Bad arguments"))); - } - - StatWatcher *handler = ObjectWrap::Unwrap(args.Holder()); + StatWatcher* wrap = ObjectWrap::Unwrap(args.Holder()); String::Utf8Value path(args[0]); + const bool persistent = args[1]->BooleanValue(); + const uint32_t interval = args[2]->Uint32Value(); - assert(handler->path_ == NULL); - handler->path_ = strdup(*path); - - ev_tstamp interval = 0.; - if (args[2]->IsInt32()) { - interval = NODE_V8_UNIXTIME(args[2]); - } - - ev_stat_set(&handler->watcher_, handler->path_, interval); - ev_stat_start(EV_DEFAULT_UC_ &handler->watcher_); - - handler->persistent_ = args[1]->IsTrue(); - - if (!handler->persistent_) { - ev_unref(EV_DEFAULT_UC); - } - - handler->Ref(); + if (!persistent) uv_unref(reinterpret_cast(&wrap->watcher_)); + uv_fs_poll_start(&wrap->watcher_, Callback, *path, interval); + wrap->Ref(); return Undefined(); } @@ -110,24 +98,20 @@ Handle StatWatcher::Start(const Arguments& args) { Handle StatWatcher::Stop(const Arguments& args) { HandleScope scope; - StatWatcher *handler = ObjectWrap::Unwrap(args.Holder()); + StatWatcher* wrap = ObjectWrap::Unwrap(args.Holder()); if (onstop_sym.IsEmpty()) { onstop_sym = NODE_PSYMBOL("onstop"); } - MakeCallback(handler->handle_, onstop_sym, 0, NULL); - handler->Stop(); + MakeCallback(wrap->handle_, onstop_sym, 0, NULL); + wrap->Stop(); return Undefined(); } void StatWatcher::Stop () { - if (watcher_.active) { - if (!persistent_) ev_ref(EV_DEFAULT_UC); - ev_stat_stop(EV_DEFAULT_UC_ &watcher_); - free(path_); - path_ = NULL; - Unref(); - } + if (!uv_is_active(reinterpret_cast(&watcher_))) return; + uv_fs_poll_stop(&watcher_); + Unref(); } diff --git a/src/node_stat_watcher.h b/src/node_stat_watcher.h index 2b2d1331de2..62bbce0fc82 100644 --- a/src/node_stat_watcher.h +++ b/src/node_stat_watcher.h @@ -23,7 +23,7 @@ #define NODE_STAT_WATCHER_H_ #include "node.h" -#include "uv-private/ev.h" +#include "uv.h" namespace node { @@ -35,15 +35,11 @@ class StatWatcher : ObjectWrap { static v8::Persistent constructor_template; StatWatcher() : ObjectWrap() { - persistent_ = false; - path_ = NULL; - ev_init(&watcher_, StatWatcher::Callback); - watcher_.data = this; + uv_fs_poll_init(uv_default_loop(), &watcher_); } ~StatWatcher() { Stop(); - assert(path_ == NULL); } static v8::Handle New(const v8::Arguments& args); @@ -51,13 +47,13 @@ class StatWatcher : ObjectWrap { static v8::Handle Stop(const v8::Arguments& args); private: - static void Callback(EV_P_ ev_stat *watcher, int revents); - + static void Callback(uv_fs_poll_t* handle, + int status, + const uv_statbuf_t* prev, + const uv_statbuf_t* curr); void Stop(); - ev_stat watcher_; - bool persistent_; - char *path_; + uv_fs_poll_t watcher_; }; } // namespace node diff --git a/src/node_version.h b/src/node_version.h index 7606ac42c46..c310084ec0b 100644 --- a/src/node_version.h +++ b/src/node_version.h @@ -19,16 +19,12 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE // USE OR OTHER DEALINGS IN THE SOFTWARE. -#if 0 /* commenting out to build via gyp faster */ -#include "node_config.h" -#endif - #ifndef NODE_VERSION_H #define NODE_VERSION_H #define NODE_MAJOR_VERSION 0 -#define NODE_MINOR_VERSION 7 -#define NODE_PATCH_VERSION 10 +#define NODE_MINOR_VERSION 9 +#define NODE_PATCH_VERSION 0 #define NODE_VERSION_IS_RELEASE 0 #ifndef NODE_STRINGIFY diff --git a/src/node_win32_etw_provider-inl.h b/src/node_win32_etw_provider-inl.h new file mode 100644 index 00000000000..9d3f4e546fe --- /dev/null +++ b/src/node_win32_etw_provider-inl.h @@ -0,0 +1,145 @@ +// Copyright Joyent, Inc. and other Node 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. + +#ifndef SRC_ETW_INL_H_ +#define SRC_ETW_INL_H_ + +#include "node_win32_etw_provider.h" +#include "node_etw_provider.h" + +namespace node { + +using namespace v8; + +// From node_win32_etw_provider.cc +extern REGHANDLE node_provider; +extern EventWriteFunc event_write; +extern int events_enabled; + +#define ETW_WRITE_STRING_DATA(data_descriptor, data) \ + EventDataDescCreate(data_descriptor, \ + data, \ + (strlen(data) + 1) * sizeof(char)); + +#define ETW_WRITE_INT32_DATA(data_descriptor, data) \ + EventDataDescCreate(data_descriptor, data, sizeof(int32_t)); + +#define ETW_WRITE_NET_CONNECTION(descriptors, conn) \ + ETW_WRITE_INT32_DATA(descriptors, &conn->fd); \ + ETW_WRITE_INT32_DATA(descriptors + 1, &conn->port); \ + ETW_WRITE_STRING_DATA(descriptors + 2, conn->remote); \ + ETW_WRITE_INT32_DATA(descriptors + 3, &conn->buffered); + +#define ETW_WRITE_HTTP_SERVER_REQUEST(descriptors, req) \ + ETW_WRITE_STRING_DATA(descriptors, req->url); \ + ETW_WRITE_STRING_DATA(descriptors + 1, req->method); \ + ETW_WRITE_STRING_DATA(descriptors + 2, req->forwardedFor); + +#define ETW_WRITE_HTTP_CLIENT_REQUEST(descriptors, req) \ + ETW_WRITE_STRING_DATA(descriptors, req->url); \ + ETW_WRITE_STRING_DATA(descriptors + 1, req->method); + +#define ETW_WRITE_GC(descriptors, type, flags) \ + ETW_WRITE_INT32_DATA(descriptors, &type); \ + ETW_WRITE_INT32_DATA(descriptors + 1, &flags); + +#define ETW_WRITE_EVENT(eventDescriptor, dataDescriptors) \ + DWORD status = event_write(node_provider, \ + &eventDescriptor, \ + sizeof(dataDescriptors)/sizeof(*dataDescriptors),\ + dataDescriptors); \ + assert(status == ERROR_SUCCESS); + + +void NODE_HTTP_SERVER_REQUEST(node_dtrace_http_server_request_t* req, + node_dtrace_connection_t* conn) { + EVENT_DATA_DESCRIPTOR descriptors[7]; + ETW_WRITE_HTTP_SERVER_REQUEST(descriptors, req); + ETW_WRITE_NET_CONNECTION(descriptors + 3, conn); + ETW_WRITE_EVENT(NODE_HTTP_SERVER_REQUEST_EVENT, descriptors); +} + + +void NODE_HTTP_SERVER_RESPONSE(node_dtrace_connection_t* conn) { + EVENT_DATA_DESCRIPTOR descriptors[4]; + ETW_WRITE_NET_CONNECTION(descriptors, conn); + ETW_WRITE_EVENT(NODE_HTTP_SERVER_RESPONSE_EVENT, descriptors); +} + + +void NODE_HTTP_CLIENT_REQUEST(node_dtrace_http_client_request_t* req, + node_dtrace_connection_t* conn) { + EVENT_DATA_DESCRIPTOR descriptors[6]; + ETW_WRITE_HTTP_CLIENT_REQUEST(descriptors, req); + ETW_WRITE_NET_CONNECTION(descriptors + 2, conn); + ETW_WRITE_EVENT(NODE_HTTP_CLIENT_REQUEST_EVENT, descriptors); +} + + +void NODE_HTTP_CLIENT_RESPONSE(node_dtrace_connection_t* conn) { + EVENT_DATA_DESCRIPTOR descriptors[4]; + ETW_WRITE_NET_CONNECTION(descriptors, conn); + ETW_WRITE_EVENT(NODE_HTTP_CLIENT_RESPONSE_EVENT, descriptors); +} + + +void NODE_NET_SERVER_CONNECTION(node_dtrace_connection_t* conn) { + EVENT_DATA_DESCRIPTOR descriptors[4]; + ETW_WRITE_NET_CONNECTION(descriptors, conn); + ETW_WRITE_EVENT(NODE_NET_SERVER_CONNECTION_EVENT, descriptors); +} + + +void NODE_NET_STREAM_END(node_dtrace_connection_t* conn) { + EVENT_DATA_DESCRIPTOR descriptors[4]; + ETW_WRITE_NET_CONNECTION(descriptors, conn); + ETW_WRITE_EVENT(NODE_NET_STREAM_END_EVENT, descriptors); +} + + +void NODE_GC_START(GCType type, GCCallbackFlags flags) { + if (events_enabled > 0) { + EVENT_DATA_DESCRIPTOR descriptors[2]; + ETW_WRITE_GC(descriptors, type, flags); + ETW_WRITE_EVENT(NODE_GC_START_EVENT, descriptors); + } +} + + +void NODE_GC_DONE(GCType type, GCCallbackFlags flags) { + if (events_enabled > 0) { + EVENT_DATA_DESCRIPTOR descriptors[2]; + ETW_WRITE_GC(descriptors, type, flags); + ETW_WRITE_EVENT(NODE_GC_DONE_EVENT, descriptors); + } +} + + +bool NODE_HTTP_SERVER_REQUEST_ENABLED() { return events_enabled > 0; } +bool NODE_HTTP_SERVER_RESPONSE_ENABLED() { return events_enabled > 0; } +bool NODE_HTTP_CLIENT_REQUEST_ENABLED() { return events_enabled > 0; } +bool NODE_HTTP_CLIENT_RESPONSE_ENABLED() { return events_enabled > 0; } +bool NODE_NET_SERVER_CONNECTION_ENABLED() { return events_enabled > 0; } +bool NODE_NET_STREAM_END_ENABLED() { return events_enabled > 0; } +bool NODE_NET_SOCKET_READ_ENABLED() { return events_enabled > 0; } +bool NODE_NET_SOCKET_WRITE_ENABLED() { return events_enabled > 0; } +} +#endif // SRC_ETW_INL_H_ \ No newline at end of file diff --git a/src/node_win32_etw_provider.cc b/src/node_win32_etw_provider.cc new file mode 100644 index 00000000000..78f465c4669 --- /dev/null +++ b/src/node_win32_etw_provider.cc @@ -0,0 +1,91 @@ +// Copyright Joyent, Inc. and other Node 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. + +#include "node_dtrace.h" +#include "node_win32_etw_provider.h" +#include "node_etw_provider.h" + +namespace node { + +using namespace v8; + +HMODULE advapi; +REGHANDLE node_provider; +EventRegisterFunc event_register; +EventUnregisterFunc event_unregister; +EventWriteFunc event_write; +int events_enabled; + +// This callback is called by ETW when consumers of our provider +// are enabled or disabled. +// The callback is dispatched on ETW thread. +void NTAPI etw_events_enable_callback( + LPCGUID SourceId, + ULONG IsEnabled, + UCHAR Level, + ULONGLONG MatchAnyKeyword, + ULONGLONG MatchAllKeywords, + PEVENT_FILTER_DESCRIPTOR FilterData, + PVOID CallbackContext) { + if (IsEnabled) { + events_enabled++; + } else { + events_enabled--; + } +} + + +void init_etw() { + events_enabled = 0; + + advapi = LoadLibrary("advapi32.dll"); + if (advapi) { + event_register = (EventRegisterFunc) + GetProcAddress(advapi, "EventRegister"); + event_unregister = (EventUnregisterFunc) + GetProcAddress(advapi, "EventUnregister"); + event_write = (EventWriteFunc)GetProcAddress(advapi, "EventWrite"); + + if (event_register) { + DWORD status = event_register(&NODE_ETW_PROVIDER, + etw_events_enable_callback, + NULL, + &node_provider); + assert(status == ERROR_SUCCESS); + } + } +} + + +void shutdown_etw() { + if (advapi && event_unregister && node_provider) { + event_unregister(node_provider); + node_provider = 0; + } + + events_enabled = 0; + + if (advapi) { + FreeLibrary(advapi); + advapi = NULL; + } +} +} \ No newline at end of file diff --git a/src/node_win32_etw_provider.h b/src/node_win32_etw_provider.h new file mode 100644 index 00000000000..adfff37e568 --- /dev/null +++ b/src/node_win32_etw_provider.h @@ -0,0 +1,82 @@ +// Copyright Joyent, Inc. and other Node 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. + +#ifndef SRC_ETW_H_ +#define SRC_ETW_H_ + +#include +#include "node_dtrace.h" + +namespace node { + +using namespace v8; + +#if defined(_MSC_VER) +# define INLINE __forceinline +#else +# define INLINE inline +#endif + +typedef ULONG (NTAPI *EventRegisterFunc)( + LPCGUID ProviderId, + PENABLECALLBACK EnableCallback, + PVOID CallbackContext, + PREGHANDLE RegHandle +); + +typedef ULONG (NTAPI *EventUnregisterFunc)( + REGHANDLE RegHandle +); + +typedef ULONG (NTAPI *EventWriteFunc)( + REGHANDLE RegHandle, + PCEVENT_DESCRIPTOR EventDescriptor, + ULONG UserDataCount, + PEVENT_DATA_DESCRIPTOR UserData +); + +void init_etw(); +void shutdown_etw(); + +INLINE void NODE_HTTP_SERVER_REQUEST(node_dtrace_http_server_request_t* req, + node_dtrace_connection_t* conn); +INLINE void NODE_HTTP_SERVER_RESPONSE(node_dtrace_connection_t* conn); +INLINE void NODE_HTTP_CLIENT_REQUEST(node_dtrace_http_client_request_t* req, + node_dtrace_connection_t* conn); +INLINE void NODE_HTTP_CLIENT_RESPONSE(node_dtrace_connection_t* conn); +INLINE void NODE_NET_SERVER_CONNECTION(node_dtrace_connection_t* conn); +INLINE void NODE_NET_STREAM_END(node_dtrace_connection_t* conn); +INLINE void NODE_GC_START(GCType type, GCCallbackFlags flags); +INLINE void NODE_GC_DONE(GCType type, GCCallbackFlags flags); + +INLINE bool NODE_HTTP_SERVER_REQUEST_ENABLED(); +INLINE bool NODE_HTTP_SERVER_RESPONSE_ENABLED(); +INLINE bool NODE_HTTP_CLIENT_REQUEST_ENABLED(); +INLINE bool NODE_HTTP_CLIENT_RESPONSE_ENABLED(); +INLINE bool NODE_NET_SERVER_CONNECTION_ENABLED(); +INLINE bool NODE_NET_STREAM_END_ENABLED(); +INLINE bool NODE_NET_SOCKET_READ_ENABLED(); +INLINE bool NODE_NET_SOCKET_WRITE_ENABLED(); + +#define NODE_NET_SOCKET_READ(arg0, arg1) +#define NODE_NET_SOCKET_WRITE(arg0, arg1) +} +#endif // SRC_ETW_H_ \ No newline at end of file diff --git a/src/process_wrap.cc b/src/process_wrap.cc index 101d89b3fde..b156692ac0e 100644 --- a/src/process_wrap.cc +++ b/src/process_wrap.cc @@ -67,6 +67,9 @@ class ProcessWrap : public HandleWrap { NODE_SET_PROTOTYPE_METHOD(constructor, "spawn", Spawn); NODE_SET_PROTOTYPE_METHOD(constructor, "kill", Kill); + NODE_SET_PROTOTYPE_METHOD(constructor, "ref", HandleWrap::Ref); + NODE_SET_PROTOTYPE_METHOD(constructor, "unref", HandleWrap::Unref); + target->Set(String::NewSymbol("Process"), constructor->GetFunction()); } @@ -103,7 +106,8 @@ class ProcessWrap : public HandleWrap { if (type->Equals(String::NewSymbol("ignore"))) { options->stdio[i].flags = UV_IGNORE; } else if (type->Equals(String::NewSymbol("pipe"))) { - options->stdio[i].flags = UV_CREATE_PIPE; + options->stdio[i].flags = static_cast( + UV_CREATE_PIPE | UV_READABLE_PIPE | UV_WRITABLE_PIPE); options->stdio[i].data.stream = reinterpret_cast( PipeWrap::Unwrap(stdio ->Get(String::NewSymbol("handle")).As())->UVHandle()); @@ -233,6 +237,11 @@ class ProcessWrap : public HandleWrap { options.flags |= UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS; } + //options.detached + if (js_options->Get(String::NewSymbol("detached"))->IsTrue()) { + options.flags |= UV_PROCESS_DETACHED; + } + int r = uv_spawn(uv_default_loop(), &wrap->process_, options); if (r) { diff --git a/src/res/node.ico b/src/res/node.ico new file mode 100644 index 00000000000..dad74d3cc0c Binary files /dev/null and b/src/res/node.ico differ diff --git a/tools/msvs/res/node.rc b/src/res/node.rc similarity index 100% rename from tools/msvs/res/node.rc rename to src/res/node.rc diff --git a/src/res/node_etw_provider.man b/src/res/node_etw_provider.man new file mode 100644 index 00000000000..2d96a20c31a --- /dev/null +++ b/src/res/node_etw_provider.man @@ -0,0 +1,102 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/slab_allocator.cc b/src/slab_allocator.cc index 45daf621a9e..e0d7b131321 100644 --- a/src/slab_allocator.cc +++ b/src/slab_allocator.cc @@ -37,6 +37,7 @@ using v8::Object; using v8::Persistent; using v8::String; using v8::Value; +using v8::V8; namespace node { @@ -49,10 +50,11 @@ SlabAllocator::SlabAllocator(unsigned int size) { SlabAllocator::~SlabAllocator() { if (!initialized_) return; - slab_sym_.Clear(); + if (V8::IsDead()) return; slab_sym_.Dispose(); - slab_.Clear(); + slab_sym_.Clear(); slab_.Dispose(); + slab_.Clear(); } @@ -92,8 +94,8 @@ char* SlabAllocator::Allocate(Handle obj, unsigned int size) { } if (slab_.IsEmpty() || offset_ + size > size_) { - slab_.Clear(); slab_.Dispose(); + slab_.Clear(); slab_ = Persistent::New(NewSlab(size_)); offset_ = 0; last_ptr_ = NULL; diff --git a/src/stream_wrap.cc b/src/stream_wrap.cc index aaa5cc609b1..e79d212c43a 100644 --- a/src/stream_wrap.cc +++ b/src/stream_wrap.cc @@ -76,14 +76,23 @@ static Persistent bytes_sym; static Persistent write_queue_size_sym; static Persistent onread_sym; static Persistent oncomplete_sym; -static SlabAllocator slab_allocator(SLAB_SIZE); +static SlabAllocator* slab_allocator; static bool initialized; +static void DeleteSlabAllocator(void*) { + delete slab_allocator; + slab_allocator = NULL; +} + + void StreamWrap::Initialize(Handle target) { if (initialized) return; initialized = true; + slab_allocator = new SlabAllocator(SLAB_SIZE); + AtExit(DeleteSlabAllocator, NULL); + HandleScope scope; HandleWrap::Initialize(target); @@ -156,7 +165,7 @@ Handle StreamWrap::ReadStop(const Arguments& args) { uv_buf_t StreamWrap::OnAlloc(uv_handle_t* handle, size_t suggested_size) { StreamWrap* wrap = static_cast(handle->data); assert(wrap->stream_ == reinterpret_cast(handle)); - char* buf = slab_allocator.Allocate(wrap->object_, suggested_size); + char* buf = slab_allocator->Allocate(wrap->object_, suggested_size); return uv_buf_init(buf, suggested_size); } @@ -175,7 +184,7 @@ void StreamWrap::OnReadCommon(uv_stream_t* handle, ssize_t nread, // If libuv reports an error or EOF it *may* give us a buffer back. In that // case, return the space to the slab. if (buf.base != NULL) { - slab_allocator.Shrink(wrap->object_, buf.base, 0); + slab_allocator->Shrink(wrap->object_, buf.base, 0); } SetErrno(uv_last_error(uv_default_loop())); @@ -184,9 +193,9 @@ void StreamWrap::OnReadCommon(uv_stream_t* handle, ssize_t nread, } assert(buf.base != NULL); - Local slab = slab_allocator.Shrink(wrap->object_, - buf.base, - nread); + Local slab = slab_allocator->Shrink(wrap->object_, + buf.base, + nread); if (nread == 0) return; assert(static_cast(nread) <= buf.len); diff --git a/src/udp_wrap.cc b/src/udp_wrap.cc index b0f8bad1f8b..c5f0aa76da3 100644 --- a/src/udp_wrap.cc +++ b/src/udp_wrap.cc @@ -58,7 +58,13 @@ Local AddressToJS(const sockaddr* addr); static Persistent buffer_sym; static Persistent oncomplete_sym; static Persistent onmessage_sym; -static SlabAllocator slab_allocator(SLAB_SIZE); +static SlabAllocator* slab_allocator; + + +static void DeleteSlabAllocator(void*) { + delete slab_allocator; + slab_allocator = NULL; +} UDPWrap::UDPWrap(Handle object): HandleWrap(object, @@ -76,6 +82,9 @@ UDPWrap::~UDPWrap() { void UDPWrap::Initialize(Handle target) { HandleWrap::Initialize(target); + slab_allocator = new SlabAllocator(SLAB_SIZE); + AtExit(DeleteSlabAllocator, NULL); + HandleScope scope; buffer_sym = NODE_PSYMBOL("buffer"); @@ -352,7 +361,7 @@ void UDPWrap::OnSend(uv_udp_send_t* req, int status) { uv_buf_t UDPWrap::OnAlloc(uv_handle_t* handle, size_t suggested_size) { UDPWrap* wrap = static_cast(handle->data); - char* buf = slab_allocator.Allocate(wrap->object_, suggested_size); + char* buf = slab_allocator->Allocate(wrap->object_, suggested_size); return uv_buf_init(buf, suggested_size); } @@ -365,9 +374,9 @@ void UDPWrap::OnRecv(uv_udp_t* handle, HandleScope scope; UDPWrap* wrap = reinterpret_cast(handle->data); - Local slab = slab_allocator.Shrink(wrap->object_, - buf.base, - nread < 0 ? 0 : nread); + Local slab = slab_allocator->Shrink(wrap->object_, + buf.base, + nread < 0 ? 0 : nread); if (nread == 0) return; if (nread < 0) { diff --git a/test/fixtures/child-process-persistent.js b/test/fixtures/child-process-persistent.js new file mode 100644 index 00000000000..226ab3329d9 --- /dev/null +++ b/test/fixtures/child-process-persistent.js @@ -0,0 +1 @@ +setInterval(function () {}, 500); diff --git a/test/fixtures/deprecated.js b/test/fixtures/deprecated.js new file mode 100644 index 00000000000..be4bc4ae0d3 --- /dev/null +++ b/test/fixtures/deprecated.js @@ -0,0 +1 @@ +require('util').p('This is deprecated'); diff --git a/test/fixtures/parent-process-nonpersistent.js b/test/fixtures/parent-process-nonpersistent.js new file mode 100644 index 00000000000..a71d1a3882d --- /dev/null +++ b/test/fixtures/parent-process-nonpersistent.js @@ -0,0 +1,13 @@ + +var spawn = require('child_process').spawn, + path = require('path'), + childPath = path.join(__dirname, 'child-process-persistent.js'); + +var child = spawn(process.execPath, [ childPath ], { + detached: true, + stdio: 'ignore' +}); + +console.log(child.pid); + +child.unref(); diff --git a/test/gc/node_modules/weak/.gitignore b/test/gc/node_modules/weak/.gitignore new file mode 100644 index 00000000000..796b96d1c40 --- /dev/null +++ b/test/gc/node_modules/weak/.gitignore @@ -0,0 +1 @@ +/build diff --git a/test/gc/node_modules/weak/LICENSE b/test/gc/node_modules/weak/LICENSE new file mode 100644 index 00000000000..834ec929b0b --- /dev/null +++ b/test/gc/node_modules/weak/LICENSE @@ -0,0 +1,13 @@ +Copyright (c) 2011, Ben Noordhuis + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. \ No newline at end of file diff --git a/test/gc/node_modules/weak/README.md b/test/gc/node_modules/weak/README.md new file mode 100644 index 00000000000..9e8a9166bca --- /dev/null +++ b/test/gc/node_modules/weak/README.md @@ -0,0 +1,114 @@ +node-weak +========= +### Make weak references to JavaScript Objects. +[![Build Status](https://secure.travis-ci.org/TooTallNate/node-weak.png)](http://travis-ci.org/TooTallNate/node-weak) + +On certain rarer occasions, you run into the need to be notified when a JavaScript +object is going to be garbage collected. This feature is exposed to V8's C++ API, +but not to JavaScript. + +That's where `node-weak` comes in! This module exports V8's `Persistent` +functionality to JavaScript. This allows you to create weak references, and +optionally attach a callback function to any arbitrary JS object. The callback +function will be invoked right before the Object is garbage collected (i.e. after +there are no more remaining references to the Object in JS-land). + +This module can, for example, be used for debugging; to determine whether or not +an Object is being garbage collected as it should. +Take a look at the example below for commented walkthrough scenario. + + +Installation +------------ + +Install with `npm`: + +``` bash +$ npm install weak +``` + + +Example +------- + +Here's an example of calling a `cleanup()` function on a Object before it gets +garbage collected: + +``` js +var weak = require('weak') + +// we are going to "monitor" this Object and invoke "cleanup" +// before the object is garbage collected +var obj = { + a: true + , foo: 'bar' +} + +// The function to call before Garbage Collection. +// Note that by the time this is called, 'obj' has been set to `null`. +function cleanup (o) { + delete o.a + delete o.foo +} + +// Here's where we set up the weak reference +var ref = weak(obj, function () { + // `this` inside the callback is the 'obj'. DO NOT store any new references + // to the object, and DO NOT use the object in any async functions. + cleanup(this) +}) + +// While `obj` is alive, `ref` proxies everything to it, so: +ref.a === obj.a +ref.foo === obj.foo + +// Clear out any references to the object, so that it will be GC'd at some point... +obj = null + +// +//// Time passes, and the garbage collector is run +// + +// `callback()` above is called, and `ref` now acts like an empty object. +typeof ref.foo === 'undefined' +``` + + +API +--- + +### weakref weak(Object obj [, Function callback]) + +The main exports is the function that creates the weak reference. +The first argument is the Object that should be monitored. +The Object can be a regular Object, an Array, a Function, a RegExp, or any of +the primitive types or constructor function created with `new`. +Optionally, you can set a callback function to be invoked +before the object is garbage collected. + + +### Object weak.get(weakref ref) + +`get()` returns the actual reference to the Object that this weak reference was +created with. If this is called with a dead reference, `undefined` is returned. + + +### Boolean weak.isDead(weakref ref) + +Checks to see if `ref` is a dead reference. Returns `true` if the original Object +has already been GC'd, `false` otherwise. + + +### null weak.addCallback(weakref ref, Function callback) + +Adds `callback` to the Array of callback functions that will be invoked before the +Objects gets garbage collected. The callbacks get executed in the order that they +are added. + + +### Array weak.callbacks(weakref ref) + +Returns the internal `Array` that `ref` iterates through to invoke the GC +callbacks. The array can be `push()`ed or `unshift()`ed onto, to have more control +over the execution order of the callbacks. This is similar in concept to node's +`EventEmitter#listeners()` function. diff --git a/test/gc/node_modules/weak/binding.gyp b/test/gc/node_modules/weak/binding.gyp new file mode 100644 index 00000000000..68e9eb19913 --- /dev/null +++ b/test/gc/node_modules/weak/binding.gyp @@ -0,0 +1,8 @@ +{ + 'targets': [ + { + 'target_name': 'weakref', + 'sources': [ 'src/weakref.cc' ] + } + ] +} diff --git a/test/gc/node_modules/weak/lib/weak.js b/test/gc/node_modules/weak/lib/weak.js new file mode 100644 index 00000000000..8081a76c45f --- /dev/null +++ b/test/gc/node_modules/weak/lib/weak.js @@ -0,0 +1,18 @@ +var bindings +try { + bindings = require('../build/Release/weakref.node') +} catch (e) { + if (e.code === 'MODULE_NOT_FOUND') { + bindings = require('../build/Debug/weakref.node') + } else { + throw e + } +} +module.exports = bindings.create + +// backwards-compat with node-weakref +bindings.weaken = bindings.create + +Object.keys(bindings).forEach(function (name) { + module.exports[name] = bindings[name] +}) diff --git a/test/gc/node_modules/weak/package.json b/test/gc/node_modules/weak/package.json new file mode 100644 index 00000000000..f2e952bc876 --- /dev/null +++ b/test/gc/node_modules/weak/package.json @@ -0,0 +1,55 @@ +{ + "author": { + "name": "Ben Noordhuis", + "email": "info@bnoordhuis.nl" + }, + "contributors": [ + { + "name": "Nathan Rajlich", + "email": "nathan@tootallnate.net", + "url": "http://tootallnate.net" + } + ], + "name": "weak", + "description": "Make weak references to JavaScript Objects.", + "keywords": [ + "weak", + "reference", + "js", + "javascript", + "object", + "function", + "callback" + ], + "version": "0.2.1", + "repository": { + "type": "git", + "url": "git://github.com/TooTallNate/node-weak.git" + }, + "main": "./lib/weak.js", + "scripts": { + "test": "mocha -gc --reporter spec", + "install": "node-gyp rebuild" + }, + "engines": { + "node": "*" + }, + "dependencies": { + "bindings": "*" + }, + "devDependencies": { + "mocha": "> 0.7.0", + "should": "*" + }, + "_npmUser": { + "name": "tootallnate", + "email": "nathan@tootallnate.net" + }, + "_id": "weak@0.2.1", + "optionalDependencies": {}, + "_engineSupported": true, + "_npmVersion": "1.1.25", + "_nodeVersion": "v0.7.10", + "_defaultsLoaded": true, + "_from": "weak" +} diff --git a/test/gc/node_modules/weak/src/weakref.cc b/test/gc/node_modules/weak/src/weakref.cc new file mode 100644 index 00000000000..409b2154afa --- /dev/null +++ b/test/gc/node_modules/weak/src/weakref.cc @@ -0,0 +1,315 @@ +/* + * Copyright (c) 2011, Ben Noordhuis + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include "v8.h" +#include "node.h" + +using namespace v8; +using namespace node; + +namespace { + + +typedef struct proxy_container { + Persistent proxy; + Persistent target; + Persistent callbacks; +} proxy_container; + + +Persistent proxyClass; + + +bool IsDead(Handle proxy) { + assert(proxy->InternalFieldCount() == 1); + proxy_container *cont = reinterpret_cast( + proxy->GetPointerFromInternalField(0)); + return cont == NULL || cont->target.IsEmpty(); +} + + +Handle Unwrap(Handle proxy) { + assert(!IsDead(proxy)); + proxy_container *cont = reinterpret_cast( + proxy->GetPointerFromInternalField(0)); + return cont->target; +} + +Handle GetCallbacks(Handle proxy) { + proxy_container *cont = reinterpret_cast( + proxy->GetPointerFromInternalField(0)); + assert(cont != NULL); + return cont->callbacks; +} + + +#define UNWRAP \ + HandleScope scope; \ + Handle obj; \ + const bool dead = IsDead(info.This()); \ + if (!dead) obj = Unwrap(info.This()); \ + + +Handle WeakNamedPropertyGetter(Local property, + const AccessorInfo& info) { + UNWRAP + return dead ? Local() : obj->Get(property); +} + + +Handle WeakNamedPropertySetter(Local property, + Local value, + const AccessorInfo& info) { + UNWRAP + if (!dead) obj->Set(property, value); + return value; +} + + +Handle WeakNamedPropertyQuery(Local property, + const AccessorInfo& info) { + return HandleScope().Close(Integer::New(None)); +} + + +Handle WeakNamedPropertyDeleter(Local property, + const AccessorInfo& info) { + UNWRAP + return Boolean::New(!dead && obj->Delete(property)); +} + + +Handle WeakIndexedPropertyGetter(uint32_t index, + const AccessorInfo& info) { + UNWRAP + return dead ? Local() : obj->Get(index); +} + + +Handle WeakIndexedPropertySetter(uint32_t index, + Local value, + const AccessorInfo& info) { + UNWRAP + if (!dead) obj->Set(index, value); + return value; +} + + +Handle WeakIndexedPropertyQuery(uint32_t index, + const AccessorInfo& info) { + return HandleScope().Close(Integer::New(None)); +} + + +Handle WeakIndexedPropertyDeleter(uint32_t index, + const AccessorInfo& info) { + UNWRAP + return Boolean::New(!dead && obj->Delete(index)); +} + + +Handle WeakPropertyEnumerator(const AccessorInfo& info) { + UNWRAP + return HandleScope().Close(dead ? Array::New(0) : obj->GetPropertyNames()); +} + + +void AddCallback(Handle proxy, Handle callback) { + Handle callbacks = GetCallbacks(proxy); + callbacks->Set(Integer::New(callbacks->Length()), callback); +} + + +void TargetCallback(Persistent target, void* arg) { + HandleScope scope; + + assert(target.IsNearDeath()); + + proxy_container *cont = reinterpret_cast(arg); + + // invoke any listening callbacks + uint32_t len = cont->callbacks->Length(); + Handle argv[1]; + argv[0] = target; + for (uint32_t i=0; i cb = Handle::Cast( + cont->callbacks->Get(Integer::New(i))); + + TryCatch try_catch; + + cb->Call(target->ToObject(), 1, argv); + + if (try_catch.HasCaught()) { + FatalException(try_catch); + } + } + + cont->proxy->SetPointerInInternalField(0, NULL); + cont->proxy.Dispose(); + cont->proxy.Clear(); + cont->target.Dispose(); + cont->target.Clear(); + cont->callbacks.Dispose(); + cont->callbacks.Clear(); + free(cont); +} + + +Handle Create(const Arguments& args) { + HandleScope scope; + + if (!args[0]->IsObject()) { + Local message = String::New("Object expected"); + return ThrowException(Exception::TypeError(message)); + } + + proxy_container *cont = (proxy_container *) + malloc(sizeof(proxy_container)); + + cont->target = Persistent::New(args[0]->ToObject()); + cont->callbacks = Persistent::New(Array::New()); + + cont->proxy = Persistent::New(proxyClass->NewInstance()); + cont->proxy->SetPointerInInternalField(0, cont); + + cont->target.MakeWeak(cont, TargetCallback); + + if (args.Length() >= 2) { + AddCallback(cont->proxy, Handle::Cast(args[1])); + } + + return cont->proxy; +} + +/** + * TODO: Make this better. + */ + +bool isWeakRef (Handle val) { + return val->IsObject() && val->ToObject()->InternalFieldCount() == 1; +} + +Handle IsWeakRef (const Arguments& args) { + HandleScope scope; + return Boolean::New(isWeakRef(args[0])); +} + +Handle Get(const Arguments& args) { + HandleScope scope; + + if (!isWeakRef(args[0])) { + Local message = String::New("Weakref instance expected"); + return ThrowException(Exception::TypeError(message)); + } + Local proxy = args[0]->ToObject(); + + const bool dead = IsDead(proxy); + if (dead) return Undefined(); + + Handle obj = Unwrap(proxy); + return scope.Close(obj); +} + +Handle IsNearDeath(const Arguments& args) { + HandleScope scope; + + if (!isWeakRef(args[0])) { + Local message = String::New("Weakref instance expected"); + return ThrowException(Exception::TypeError(message)); + } + Local proxy = args[0]->ToObject(); + + proxy_container *cont = reinterpret_cast( + proxy->GetPointerFromInternalField(0)); + assert(cont != NULL); + + Handle rtn = Boolean::New(cont->target.IsNearDeath()); + + return scope.Close(rtn); +} + +Handle IsDead(const Arguments& args) { + HandleScope scope; + + if (!isWeakRef(args[0])) { + Local message = String::New("Weakref instance expected"); + return ThrowException(Exception::TypeError(message)); + } + Local proxy = args[0]->ToObject(); + + const bool dead = IsDead(proxy); + return Boolean::New(dead); +} + + +Handle AddCallback(const Arguments& args) { + HandleScope scope; + + if (!isWeakRef(args[0])) { + Local message = String::New("Weakref instance expected"); + return ThrowException(Exception::TypeError(message)); + } + Local proxy = args[0]->ToObject(); + + AddCallback(proxy, Handle::Cast(args[1])); + + return Undefined(); +} + +Handle Callbacks(const Arguments& args) { + HandleScope scope; + + if (!isWeakRef(args[0])) { + Local message = String::New("Weakref instance expected"); + return ThrowException(Exception::TypeError(message)); + } + Local proxy = args[0]->ToObject(); + + return scope.Close(GetCallbacks(proxy)); +} + + +void Initialize(Handle target) { + HandleScope scope; + + proxyClass = Persistent::New(ObjectTemplate::New()); + proxyClass->SetNamedPropertyHandler(WeakNamedPropertyGetter, + WeakNamedPropertySetter, + WeakNamedPropertyQuery, + WeakNamedPropertyDeleter, + WeakPropertyEnumerator); + proxyClass->SetIndexedPropertyHandler(WeakIndexedPropertyGetter, + WeakIndexedPropertySetter, + WeakIndexedPropertyQuery, + WeakIndexedPropertyDeleter, + WeakPropertyEnumerator); + proxyClass->SetInternalFieldCount(1); + + NODE_SET_METHOD(target, "get", Get); + NODE_SET_METHOD(target, "create", Create); + NODE_SET_METHOD(target, "isWeakRef", IsWeakRef); + NODE_SET_METHOD(target, "isNearDeath", IsNearDeath); + NODE_SET_METHOD(target, "isDead", IsDead); + NODE_SET_METHOD(target, "callbacks", Callbacks); + NODE_SET_METHOD(target, "addCallback", AddCallback); + +} + +} // anonymous namespace + +NODE_MODULE(weakref, Initialize); diff --git a/test/gc/test-net-timeout.js b/test/gc/test-net-timeout.js index 52f1176174d..91d314b03d0 100644 --- a/test/gc/test-net-timeout.js +++ b/test/gc/test-net-timeout.js @@ -56,9 +56,14 @@ function status() { console.log('Done: %d/%d', done, todo); console.log('Collected: %d/%d', countGC, count); if (done === todo) { - console.log('All should be collected now.'); - assert(count === countGC); - process.exit(0); + /* Give libuv some time to make close callbacks. */ + setTimeout(function() { + gc(); + console.log('All should be collected now.'); + console.log('Collected: %d/%d', countGC, count); + assert(count === countGC); + process.exit(0); + }, 200); } } diff --git a/test/message/throw_in_line_with_tabs.out b/test/message/throw_in_line_with_tabs.out index d301495b443..d91f8c08c33 100644 --- a/test/message/throw_in_line_with_tabs.out +++ b/test/message/throw_in_line_with_tabs.out @@ -1,6 +1,6 @@ before -*/test/message/throw_in_line_with_tabs.js:32 +*test*message*throw_in_line_with_tabs.js:32 throw ({ foo: 'bar' }); ^ [object Object] diff --git a/test/message/throw_non_error.out b/test/message/throw_non_error.out index 23e3d928e83..378874f9907 100644 --- a/test/message/throw_non_error.out +++ b/test/message/throw_non_error.out @@ -1,6 +1,6 @@ before -*/test/message/throw_non_error.js:31 +*test*message*throw_non_error.js:31 throw ({ foo: 'bar' }); ^ [object Object] diff --git a/test/pummel/test-child-process-spawn-loop.js b/test/pummel/test-child-process-spawn-loop.js index d58f049e68b..631d9fc473f 100644 --- a/test/pummel/test-child-process-spawn-loop.js +++ b/test/pummel/test-child-process-spawn-loop.js @@ -46,7 +46,7 @@ function doSpawn(i) { console.log('stderr: ' + chunk); }); - child.on('exit', function() { + child.on('close', function() { // + 1 for \n or + 2 for \r\n on Windows assert.equal(SIZE + (is_windows ? 2 : 1), count); if (i < N) { diff --git a/test/pummel/test-dh-regr.js b/test/pummel/test-dh-regr.js new file mode 100644 index 00000000000..2e626bd0b77 --- /dev/null +++ b/test/pummel/test-dh-regr.js @@ -0,0 +1,41 @@ +// Copyright Joyent, Inc. and other Node 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. + +var common = require('../common'); +var assert = require('assert'); + +var crypto = require('crypto'); + +var p = crypto.createDiffieHellman(256).getPrime(); + +for (var i = 0; i < 2000; i++) { + var a = crypto.createDiffieHellman(p), + b = crypto.createDiffieHellman(p); + + a.generateKeys(); + b.generateKeys(); + + assert.equal( + a.computeSecret(b.getPublicKey()), + b.computeSecret(a.getPublicKey()), + 'secrets should be equal!' + ); +} diff --git a/test/pummel/test-exec.js b/test/pummel/test-exec.js index 70771ab4e19..6eacda783c5 100644 --- a/test/pummel/test-exec.js +++ b/test/pummel/test-exec.js @@ -22,10 +22,23 @@ var common = require('../common'); var assert = require('assert'); var exec = require('child_process').exec; + +if (process.platform !== 'win32') { + // Unix. + var SLEEP3_COMMAND = "sleep 3"; +} else { + // Windows: `choice` is a command built into cmd.exe. Use another cmd process + // to create a process tree, so we can catch bugs related to it. + var SLEEP3_COMMAND = "cmd /c choice /t 3 /c X /d X"; +} + + var success_count = 0; var error_count = 0; -exec('ls /', function(err, stdout, stderr) { + +exec(process.execPath + ' -p -e process.versions', + function(err, stdout, stderr) { if (err) { error_count++; console.log('error!: ' + err.code); @@ -39,7 +52,7 @@ exec('ls /', function(err, stdout, stderr) { }); -exec('ls /DOES_NOT_EXIST', function(err, stdout, stderr) { +exec('thisisnotavalidcommand', function(err, stdout, stderr) { if (err) { error_count++; assert.equal('', stdout); @@ -59,7 +72,7 @@ exec('ls /DOES_NOT_EXIST', function(err, stdout, stderr) { var sleeperStart = new Date(); -exec('sleep 3', { timeout: 50 }, function(err, stdout, stderr) { +exec(SLEEP3_COMMAND, { timeout: 50 }, function(err, stdout, stderr) { var diff = (new Date()) - sleeperStart; console.log('\'sleep 3\' with timeout 50 took %d ms', diff); assert.ok(diff < 500); @@ -72,7 +85,7 @@ exec('sleep 3', { timeout: 50 }, function(err, stdout, stderr) { var startSleep3 = new Date(); -var killMeTwice = exec('sleep 3', {timeout: 1000}, killMeTwiceCallback); +var killMeTwice = exec(SLEEP3_COMMAND, {timeout: 1000}, killMeTwiceCallback); process.nextTick(function() { console.log('kill pid %d', killMeTwice.pid); @@ -85,9 +98,8 @@ process.nextTick(function() { function killMeTwiceCallback(err, stdout, stderr) { var diff = (new Date()) - startSleep3; - // We should have already killed this process. Assert that - // the timeout still works and that we are getting the proper callback - // parameters. + // We should have already killed this process. Assert that the timeout still + // works and that we are getting the proper callback parameters. assert.ok(err); assert.ok(err.killed); assert.equal(err.signal, 'SIGTERM'); @@ -98,13 +110,13 @@ function killMeTwiceCallback(err, stdout, stderr) { } - exec('python -c "print 200000*\'C\'"', {maxBuffer: 1000}, function(err, stdout, stderr) { assert.ok(err); assert.ok(/maxBuffer/.test(err.message)); }); + process.on('exit', function() { assert.equal(1, success_count); assert.equal(1, error_count); diff --git a/test/pummel/test-fs-watch-file-slow.js b/test/pummel/test-fs-watch-file-slow.js new file mode 100644 index 00000000000..4124e0b2722 --- /dev/null +++ b/test/pummel/test-fs-watch-file-slow.js @@ -0,0 +1,73 @@ +// Copyright Joyent, Inc. and other Node 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. + +var common = require('../common'); +var assert = require('assert'); +var path = require('path'); +var fs = require('fs'); + +var FILENAME = path.join(common.tmpDir, 'watch-me'); +var TIMEOUT = 1300; + +var nevents = 0; + +try { + fs.unlinkSync(FILENAME); +} +catch (e) { + // swallow +} + +fs.watchFile(FILENAME, {interval:TIMEOUT - 250}, function(curr, prev) { + console.log([curr, prev]); + switch (++nevents) { + case 1: + case 2: + assert.equal(fs.existsSync(FILENAME), true); + break; + case 3: + assert.equal(fs.existsSync(FILENAME), false); + fs.unwatchFile(FILENAME); + break; + default: + assert(0); + } +}); + +process.on('exit', function() { + assert.equal(nevents, 3); +}); + +setTimeout(createFile, TIMEOUT); + +function createFile() { + fs.writeFileSync(FILENAME, "test"); + setTimeout(touchFile, TIMEOUT); +} + +function touchFile() { + fs.writeFileSync(FILENAME, "test"); + setTimeout(removeFile, TIMEOUT); +} + +function removeFile() { + fs.unlinkSync(FILENAME); +} diff --git a/test/pummel/test-fs-watch-file.js b/test/pummel/test-fs-watch-file.js index 49455a197fb..3df28af56fc 100644 --- a/test/pummel/test-fs-watch-file.js +++ b/test/pummel/test-fs-watch-file.js @@ -19,12 +19,6 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE // USE OR OTHER DEALINGS IN THE SOFTWARE. -// fs.watchFile is not available on Windows -if (process.platform === 'win32') { - process.exit(0); -} - - var common = require('../common'); var assert = require('assert'); var path = require('path'); diff --git a/test/pummel/test-net-connect-econnrefused.js b/test/pummel/test-net-connect-econnrefused.js index a6fed70dbe0..bb3ef5945e3 100644 --- a/test/pummel/test-net-connect-econnrefused.js +++ b/test/pummel/test-net-connect-econnrefused.js @@ -25,19 +25,25 @@ var common = require('../common'); var assert = require('assert'); var net = require('net'); -var ROUNDS = 1024; +var ROUNDS = 5; +var ATTEMPTS_PER_ROUND = 200; var rounds = 0; var reqs = 0; pummel(); function pummel() { - net.createConnection(common.PORT).on('error', function(err) { - assert.equal(err.code, 'ECONNREFUSED'); - if (++rounds < ROUNDS) return pummel(); - check(); - }); - reqs++; + console.log('Round', rounds, '/', ROUNDS); + + for (var pending = 0; pending < ATTEMPTS_PER_ROUND; pending++) { + net.createConnection(common.PORT).on('error', function(err) { + assert.equal(err.code, 'ECONNREFUSED'); + if (--pending > 0) return; + if (++rounds < ROUNDS) return pummel(); + check(); + }); + reqs++; + } } function check() { @@ -53,6 +59,6 @@ var check_called = false; process.on('exit', function() { assert.equal(rounds, ROUNDS); - assert.equal(reqs, ROUNDS); + assert.equal(reqs, ROUNDS * ATTEMPTS_PER_ROUND); assert(check_called); }); diff --git a/test/pummel/test-tls-ci-reneg-attack.js b/test/pummel/test-tls-ci-reneg-attack.js index e9748c116f1..778e288ca71 100644 --- a/test/pummel/test-tls-ci-reneg-attack.js +++ b/test/pummel/test-tls-ci-reneg-attack.js @@ -49,11 +49,14 @@ function test(next) { key: fs.readFileSync(common.fixturesDir + '/test_key.pem') }; + var seenError = false; + var server = tls.createServer(options, function(conn) { conn.on('error', function(err) { console.error('Caught exception: ' + err); assert(/TLS session renegotiation attack/.test(err)); conn.destroy(); + seenError = true; }); conn.pipe(conn); }); @@ -67,16 +70,17 @@ function test(next) { // count handshakes, start the attack after the initial handshake is done var handshakes = 0; + var renegs = 0; + child.stderr.on('data', function(data) { + if (seenError) return; handshakes += (('' + data).match(/verify return:1/g) || []).length; if (handshakes === 2) spam(); + renegs += (('' + data).match(/RENEGOTIATING/g) || []).length; }); child.on('exit', function() { - // with a renegotiation limit <= 1, we always see 4 handshake markers: - // two for the initial handshake and another two for the attempted - // renegotiation - assert.equal(handshakes, 2 * Math.max(2, tls.CLIENT_RENEG_LIMIT)); + assert.equal(renegs, tls.CLIENT_RENEG_LIMIT + 1); server.close(); process.nextTick(next); }); @@ -94,7 +98,7 @@ function test(next) { function spam() { if (closed) return; child.stdin.write('R\n'); - setTimeout(spam, 250); + setTimeout(spam, 50); } }); } diff --git a/test/pummel/test-watch-file.js b/test/pummel/test-watch-file.js index 3cdc3d67f56..1a3d854101c 100644 --- a/test/pummel/test-watch-file.js +++ b/test/pummel/test-watch-file.js @@ -19,11 +19,6 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE // USE OR OTHER DEALINGS IN THE SOFTWARE. -// fs.watchFile is not available on Windows -if (process.platform === 'win32') { - process.exit(0); -} - var common = require('../common'); var assert = require('assert'); diff --git a/test/simple/test-bad-unicode.js b/test/simple/test-bad-unicode.js new file mode 100644 index 00000000000..0e57909a60f --- /dev/null +++ b/test/simple/test-bad-unicode.js @@ -0,0 +1,31 @@ +// Copyright Joyent, Inc. and other Node 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. + +var assert = require('assert'), + exception = null; + +try { + eval('"\\uc/ef"'); +} catch (e) { + exception = e; +} + +assert(exception instanceof SyntaxError); diff --git a/test/simple/test-buffer-concat.js b/test/simple/test-buffer-concat.js new file mode 100644 index 00000000000..858d6924f95 --- /dev/null +++ b/test/simple/test-buffer-concat.js @@ -0,0 +1,41 @@ +// Copyright Joyent, Inc. and other Node 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. + +var common = require('../common'); +var assert = require('assert'); + +var zero = []; +var one = [ new Buffer('asdf') ]; +var long = []; +for (var i = 0; i < 10; i++) long.push(new Buffer('asdf')); + +var flatZero = Buffer.concat(zero); +var flatOne = Buffer.concat(one); +var flatLong = Buffer.concat(long); +var flatLongLen = Buffer.concat(long, 40); + +assert(flatZero.length === 0); +assert(flatOne.toString() === 'asdf'); +assert(flatOne === one[0]); +assert(flatLong.toString() === (new Array(10+1).join('asdf'))); +assert(flatLongLen.toString() === (new Array(10+1).join('asdf'))); + +console.log("ok"); diff --git a/test/simple/test-buffer.js b/test/simple/test-buffer.js index b64a6e5933c..847fbc58421 100644 --- a/test/simple/test-buffer.js +++ b/test/simple/test-buffer.js @@ -724,3 +724,6 @@ var a = Buffer(3); var b = Buffer('xxx'); a.write('aaaaaaaa', 'base64'); assert.equal(b.toString(), 'xxx'); + +// issue GH-3416 +Buffer(Buffer(0), 0, 0); diff --git a/test/simple/test-child-process-detached.js b/test/simple/test-child-process-detached.js new file mode 100644 index 00000000000..10ce5d15274 --- /dev/null +++ b/test/simple/test-child-process-detached.js @@ -0,0 +1,45 @@ +// Copyright Joyent, Inc. and other Node 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. + +var common = require('../common'); +var assert = require('assert'); +var path = require('path'); + +var spawn = require('child_process').spawn; +var childPath = path.join(__dirname, '..', 'fixtures', 'parent-process-nonpersistent.js'); +var persistentPid = -1; + +var child = spawn(process.execPath, [ childPath ]); + +child.stdout.on('data', function (data) { + persistentPid = parseInt(data, 10); +}); + +process.on('exit', function () { + assert(persistentPid !== -1); + assert.throws(function () { + process.kill(child.pid); + }); + assert.doesNotThrow(function () { + process.kill(persistentPid); + }); +}); + diff --git a/test/simple/test-child-process-fork-net.js b/test/simple/test-child-process-fork-net.js index 6dd0e5fde38..39b22d2ab47 100644 --- a/test/simple/test-child-process-fork-net.js +++ b/test/simple/test-child-process-fork-net.js @@ -157,8 +157,15 @@ if (process.argv[2] === 'child') { console.log('PARENT: server closed'); callback(); }); - server.listen(common.PORT, function() { - var connect = net.connect(common.PORT); + // don't listen on the same port, because SmartOS sometimes says + // that the server's fd is closed, but it still cannot listen + // on the same port again. + // + // An isolated test for this would be lovely, but for now, this + // will have to do. + server.listen(common.PORT + 1, function() { + console.error('testSocket, listening'); + var connect = net.connect(common.PORT + 1); var store = ''; connect.on('data', function(chunk) { store += chunk; diff --git a/test/simple/test-child-process-fork3.js b/test/simple/test-child-process-fork3.js deleted file mode 100644 index a8a8985f058..00000000000 --- a/test/simple/test-child-process-fork3.js +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright Joyent, Inc. and other Node 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. - -var common = require('../common'); -var assert = require('assert'); -var fork = require('child_process').fork; - -var filename = common.fixturesDir + '/destroy-stdin.js'; - -// Ensure that we don't accidentally close fd 0 and -// reuse it for something else, it causes all kinds -// of obscure bugs. -process.stdin.destroy(); -fork(filename).stdin.on('end', process.exit); diff --git a/test/simple/test-child-process-kill.js b/test/simple/test-child-process-kill.js index 7bb57a5e17d..08a0185d33a 100644 --- a/test/simple/test-child-process-kill.js +++ b/test/simple/test-child-process-kill.js @@ -37,10 +37,6 @@ var gotStderrEOF = false; var cat = spawn(is_windows ? 'cmd' : 'cat'); -cat.stdout.on('data', function(chunk) { - assert.ok(false); -}); - cat.stdout.on('end', function() { gotStdoutEOF = true; }); diff --git a/test/simple/test-child-process-stdout-flush.js b/test/simple/test-child-process-stdout-flush.js index 8dc39c3a5b8..adb33f5c035 100644 --- a/test/simple/test-child-process-stdout-flush.js +++ b/test/simple/test-child-process-stdout-flush.js @@ -46,7 +46,7 @@ child.stdout.on('data', function(data) { console.log(count); }); -child.on('exit', function(data) { +child.on('close', function(data) { assert.equal(n, count); console.log('okay'); }); diff --git a/test/simple/test-cluster-basic.js b/test/simple/test-cluster-basic.js index 93a3c9bf9bb..9e6b8d9fbc5 100644 --- a/test/simple/test-cluster-basic.js +++ b/test/simple/test-cluster-basic.js @@ -112,6 +112,7 @@ else if (cluster.isMaster) { //Create worker worker = cluster.fork(); + assert.equal(worker.id, 1); assert.ok(worker instanceof cluster.Worker, 'the worker is not a instance of the Worker constructor'); @@ -135,7 +136,8 @@ else if (cluster.isMaster) { assert.equal(arguments.length, 1); var expect = { address: '127.0.0.1', port: common.PORT, - addressType: 4 }; + addressType: 4, + fd: undefined }; assert.deepEqual(arguments[0], expect); break; diff --git a/test/simple/test-cluster-http-pipe.js b/test/simple/test-cluster-http-pipe.js index 47374d9b33b..46d429ad6d3 100644 --- a/test/simple/test-cluster-http-pipe.js +++ b/test/simple/test-cluster-http-pipe.js @@ -19,6 +19,11 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE // USE OR OTHER DEALINGS IN THE SOFTWARE. +// It is not possible to send pipe handles over the IPC pipe on Windows. +if (process.platform === 'win32') { + process.exit(0); +} + var common = require('../common'); var assert = require('assert'); var cluster = require('cluster'); diff --git a/test/simple/test-cluster-message.js b/test/simple/test-cluster-message.js index e60fbf0cb05..313355f7f6d 100644 --- a/test/simple/test-cluster-message.js +++ b/test/simple/test-cluster-message.js @@ -32,23 +32,34 @@ function forEach(obj, fn) { } if (cluster.isWorker) { - // Create a tcp server - // this will be used as cluster-shared-server - // and as an alternativ IPC channel + // Create a tcp server. This will be used as cluster-shared-server and as an + // alternative IPC channel. var server = net.Server(); - server.on('connection', function(socket) { - - // Tell master using TCP socket that a message is received - process.on('message', function(message) { - socket.write(JSON.stringify({ - code: 'received message', - echo: message - })); - }); + var socket, message; + + function maybeReply() { + if (!socket || !message) return; + + // Tell master using TCP socket that a message is received. + socket.write(JSON.stringify({ + code: 'received message', + echo: message + })); + } + + server.on('connection', function(socket_) { + socket = socket_; + maybeReply(); + // Send a message back over the IPC channel. process.send('message from worker'); }); + process.on('message', function(message_) { + message = message_; + maybeReply(); + }); + server.listen(common.PORT, '127.0.0.1'); } @@ -93,8 +104,7 @@ else if (cluster.isMaster) { worker.on('listening', function() { client = net.connect(common.PORT, function() { - - //Send message to worker + // Send message to worker. worker.send('message from master'); }); @@ -105,7 +115,7 @@ else if (cluster.isMaster) { if (data.code === 'received message') { check('worker', data.echo === 'message from master'); } else { - throw new Error('worng TCP message recived: ' + data); + throw new Error('wrong TCP message recived: ' + data); } }); @@ -117,7 +127,6 @@ else if (cluster.isMaster) { worker.on('exit', function() { process.exit(0); }); - }); process.once('exit', function() { diff --git a/test/simple/test-cluster-worker-kill.js b/test/simple/test-cluster-worker-kill.js index 9fd13ad65ef..284b83e7fe2 100644 --- a/test/simple/test-cluster-worker-kill.js +++ b/test/simple/test-cluster-worker-kill.js @@ -21,7 +21,7 @@ // test-cluster-worker-kill.js -// verifies that, when a child process is killed (we use SIGHUP) +// verifies that, when a child process is killed (we use SIGKILL) // - the parent receives the proper events in the proper order, no duplicates // - the exitCode and signalCode are correct in the 'exit' event // - the worker.suicide flag, and worker.state are correct @@ -40,7 +40,7 @@ if (cluster.isWorker) { } else if (cluster.isMaster) { - var KILL_SIGNAL = 'SIGHUP', + var KILL_SIGNAL = 'SIGKILL', expected_results = { cluster_emitDisconnect: [1, "the cluster did not emit 'disconnect'"], cluster_emitExit: [1, "the cluster did not emit 'exit'"], diff --git a/test/simple/test-crypto.js b/test/simple/test-crypto.js index 7a23cdf4945..de8c1a9d638 100644 --- a/test/simple/test-crypto.js +++ b/test/simple/test-crypto.js @@ -424,54 +424,77 @@ var verified = crypto.createVerify('RSA-SHA256') .verify(certPem, s2); // binary assert.strictEqual(verified, true, 'sign and verify (binary)'); -// Test encryption and decryption -var plaintext = 'Keep this a secret? No! Tell everyone about node.js!'; -var cipher = crypto.createCipher('aes192', 'MySecretKey123'); -// encrypt plaintext which is in utf8 format -// to a ciphertext which will be in hex -var ciph = cipher.update(plaintext, 'utf8', 'hex'); -// Only use binary or hex, not base64. -ciph += cipher.final('hex'); +function testCipher1(key) { + // Test encryption and decryption + var plaintext = 'Keep this a secret? No! Tell everyone about node.js!'; + var cipher = crypto.createCipher('aes192', key); -var decipher = crypto.createDecipher('aes192', 'MySecretKey123'); -var txt = decipher.update(ciph, 'hex', 'utf8'); -txt += decipher.final('utf8'); + // encrypt plaintext which is in utf8 format + // to a ciphertext which will be in hex + var ciph = cipher.update(plaintext, 'utf8', 'hex'); + // Only use binary or hex, not base64. + ciph += cipher.final('hex'); -assert.equal(txt, plaintext, 'encryption and decryption'); + var decipher = crypto.createDecipher('aes192', key); + var txt = decipher.update(ciph, 'hex', 'utf8'); + txt += decipher.final('utf8'); -// encryption and decryption with Base64 -// reported in https://github.com/joyent/node/issues/738 -var plaintext = - '32|RmVZZkFUVmpRRkp0TmJaUm56ZU9qcnJkaXNNWVNpTTU*|iXmckfRWZBGWWELw' + - 'eCBsThSsfUHLeRe0KCsK8ooHgxie0zOINpXxfZi/oNG7uq9JWFVCk70gfzQH8ZUJjAfaFg**'; -var cipher = crypto.createCipher('aes256', '0123456789abcdef'); + assert.equal(txt, plaintext, 'encryption and decryption'); +} + + +function testCipher2(key) { + // encryption and decryption with Base64 + // reported in https://github.com/joyent/node/issues/738 + var plaintext = + '32|RmVZZkFUVmpRRkp0TmJaUm56ZU9qcnJkaXNNWVNpTTU*|iXmckfRWZBGWWELw' + + 'eCBsThSsfUHLeRe0KCsK8ooHgxie0zOINpXxfZi/oNG7uq9JWFVCk70gfzQH8ZUJ' + + 'jAfaFg**'; + var cipher = crypto.createCipher('aes256', key); -// encrypt plaintext which is in utf8 format -// to a ciphertext which will be in Base64 -var ciph = cipher.update(plaintext, 'utf8', 'base64'); -ciph += cipher.final('base64'); + // encrypt plaintext which is in utf8 format + // to a ciphertext which will be in Base64 + var ciph = cipher.update(plaintext, 'utf8', 'base64'); + ciph += cipher.final('base64'); -var decipher = crypto.createDecipher('aes256', '0123456789abcdef'); -var txt = decipher.update(ciph, 'base64', 'utf8'); -txt += decipher.final('utf8'); + var decipher = crypto.createDecipher('aes256', key); + var txt = decipher.update(ciph, 'base64', 'utf8'); + txt += decipher.final('utf8'); + + assert.equal(txt, plaintext, 'encryption and decryption with Base64'); +} -assert.equal(txt, plaintext, 'encryption and decryption with Base64'); + +function testCipher3(key, iv) { + // Test encyrption and decryption with explicit key and iv + var plaintext = + '32|RmVZZkFUVmpRRkp0TmJaUm56ZU9qcnJkaXNNWVNpTTU*|iXmckfRWZBGWWELw' + + 'eCBsThSsfUHLeRe0KCsK8ooHgxie0zOINpXxfZi/oNG7uq9JWFVCk70gfzQH8ZUJ' + + 'jAfaFg**'; + var cipher = crypto.createCipheriv('des-ede3-cbc', key, iv); + var ciph = cipher.update(plaintext, 'utf8', 'hex'); + ciph += cipher.final('hex'); + + var decipher = crypto.createDecipheriv('des-ede3-cbc', key, iv); + var txt = decipher.update(ciph, 'hex', 'utf8'); + txt += decipher.final('utf8'); + + assert.equal(txt, plaintext, 'encryption and decryption with key and iv'); +} -// Test encyrption and decryption with explicit key and iv -var encryption_key = '0123456789abcd0123456789'; -var iv = '12345678'; +testCipher1('MySecretKey123'); +testCipher1(new Buffer('MySecretKey123')); -var cipher = crypto.createCipheriv('des-ede3-cbc', encryption_key, iv); -var ciph = cipher.update(plaintext, 'utf8', 'hex'); -ciph += cipher.final('hex'); +testCipher2('0123456789abcdef'); +testCipher2(new Buffer('0123456789abcdef')); -var decipher = crypto.createDecipheriv('des-ede3-cbc', encryption_key, iv); -var txt = decipher.update(ciph, 'hex', 'utf8'); -txt += decipher.final('utf8'); +testCipher3('0123456789abcd0123456789', '12345678'); +testCipher3('0123456789abcd0123456789', new Buffer('12345678')); +testCipher3(new Buffer('0123456789abcd0123456789'), '12345678'); +testCipher3(new Buffer('0123456789abcd0123456789'), new Buffer('12345678')); -assert.equal(txt, plaintext, 'encryption and decryption with key and iv'); // update() should only take buffers / strings assert.throws(function() { diff --git a/test/simple/test-deprecation-flags.js b/test/simple/test-deprecation-flags.js new file mode 100644 index 00000000000..81605da21f3 --- /dev/null +++ b/test/simple/test-deprecation-flags.js @@ -0,0 +1,57 @@ +// Copyright Joyent, Inc. and other Node 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. + +var common = require('../common'); +var assert = require('assert'); +var execFile = require('child_process').execFile; +var depmod = require.resolve('../fixtures/deprecated.js'); +var node = process.execPath; + +var normal = [depmod]; +var noDep = ['--no-deprecation', depmod]; +var traceDep = ['--trace-deprecation', depmod]; + +execFile(node, normal, function(er, stdout, stderr) { + console.error('normal: show deprecation warning'); + assert.equal(er, null); + assert.equal(stdout, ''); + assert.equal(stderr, 'util.p: Use console.error() instead.\n\'This is deprecated\'\n'); + console.log('normal ok'); +}); + +execFile(node, noDep, function(er, stdout, stderr) { + console.error('--no-deprecation: silence deprecations'); + assert.equal(er, null); + assert.equal(stdout, ''); + assert.equal(stderr, '\'This is deprecated\'\n'); + console.log('silent ok'); +}); + +execFile(node, traceDep, function(er, stdout, stderr) { + console.error('--trace-deprecation: show stack'); + assert.equal(er, null); + assert.equal(stdout, ''); + var stack = stderr.trim().split('\n'); + // just check the top and bottom. + assert.equal(stack[0], 'Trace: util.p: Use console.error() instead.'); + assert.equal(stack.pop(), '\'This is deprecated\''); + console.log('trace ok'); +}); diff --git a/test/simple/test-dgram-broadcast-multi-process.js b/test/simple/test-dgram-broadcast-multi-process.js index 7b3aa4d81e5..adbdc41098f 100644 --- a/test/simple/test-dgram-broadcast-multi-process.js +++ b/test/simple/test-dgram-broadcast-multi-process.js @@ -23,7 +23,7 @@ var common = require('../common'), assert = require('assert'), dgram = require('dgram'), util = require('util'), - assert = require('assert'), + networkInterfaces = require('os').networkInterfaces(), Buffer = require('buffer').Buffer, fork = require('child_process').fork, LOCAL_BROADCAST_HOST = '255.255.255.255', @@ -35,6 +35,19 @@ var common = require('../common'), new Buffer('Fourth message to send') ]; +// take the first non-internal interface as the address for binding +get_bindAddress: for (var name in networkInterfaces) { + var interfaces = networkInterfaces[name]; + for(var i = 0; i < interfaces.length; i++) { + var localInterface = interfaces[i]; + if (!localInterface.internal && localInterface.family === 'IPv4') { + var bindAddress = localInterface.address; + break get_bindAddress; + } + } +} +assert.ok(bindAddress); + if (process.argv[2] !== 'child') { var workers = {}, listeners = 3, @@ -146,7 +159,9 @@ if (process.argv[2] !== 'child') { var sendSocket = dgram.createSocket('udp4'); - sendSocket.bind(common.PORT); + // bind the address explicitly for sending + // INADDR_BROADCAST to only one interface + sendSocket.bind(common.PORT, bindAddress); sendSocket.setBroadcast(true); sendSocket.on('close', function() { @@ -187,6 +202,9 @@ if (process.argv[2] === 'child') { var listenSocket = dgram.createSocket('udp4'); listenSocket.on('message', function(buf, rinfo) { + // receive udp messages only sent from parent + if (rinfo.address !== bindAddress) return; + console.error('[CHILD] %s received %s from %j', process.pid, util.inspect(buf.toString()), diff --git a/test/simple/test-domain-http-server.js b/test/simple/test-domain-http-server.js index bd6336b57f1..f9962d3b8d4 100644 --- a/test/simple/test-domain-http-server.js +++ b/test/simple/test-domain-http-server.js @@ -28,7 +28,8 @@ var objects = { foo: 'bar', baz: {}, num: 42, arr: [1,2,3] }; objects.baz.asdf = objects; var serverCaught = 0; -var clientCaught = 0 +var clientCaught = 0; +var disposeEmit = 0; var server = http.createServer(function(req, res) { var dom = domain.create(); @@ -84,6 +85,10 @@ function next() { dom.dispose(); }); + dom.on('dispose', function() { + disposeEmit += 1; + }); + var req = http.get({ host: 'localhost', port: common.PORT, path: p }); dom.add(req); req.on('response', function(res) { @@ -111,5 +116,6 @@ function next() { process.on('exit', function() { assert.equal(serverCaught, 2); assert.equal(clientCaught, 2); + assert.equal(disposeEmit, 2); console.log('ok'); }); diff --git a/test/simple/test-domain-implicit-fs.js b/test/simple/test-domain-implicit-fs.js index 34e951a7683..665a821abf0 100644 --- a/test/simple/test-domain-implicit-fs.js +++ b/test/simple/test-domain-implicit-fs.js @@ -34,20 +34,13 @@ var e = new events.EventEmitter(); d.on('error', function(er) { console.error('caught', er); - switch (er.message) { - case "ENOENT, open 'this file does not exist'": - assert.equal(er.domain, d); - assert.equal(er.domain_thrown, true); - assert.ok(!er.domain_emitter); - assert.equal(er.code, 'ENOENT'); - assert.equal(er.path, 'this file does not exist'); - assert.equal(typeof er.errno, 'number'); - break; - default: - console.error('unexpected error, throwing %j', er.message); - throw er; - } + assert.strictEqual(er.domain, d); + assert.strictEqual(er.domain_thrown, true); + assert.ok(!er.domain_emitter); + assert.strictEqual(er.code, 'ENOENT'); + assert.ok(/\bthis file does not exist\b/i.test(er.path)); + assert.strictEqual(typeof er.errno, 'number'); caught++; }); diff --git a/test/simple/test-domain.js b/test/simple/test-domain.js index e20868ed0fc..ee2ddd537e8 100644 --- a/test/simple/test-domain.js +++ b/test/simple/test-domain.js @@ -34,7 +34,22 @@ var e = new events.EventEmitter(); d.on('error', function(er) { console.error('caught', er); - switch (er.message) { + + var er_message = er.message; + var er_path = er.path + + // On windows, error messages can contain full path names. If this is the + // case, remove the directory part. + if (typeof er_path === 'string') { + var slash = er_path.lastIndexOf('\\'); + if (slash !== -1) { + var dir = er_path.slice(0, slash + 1); + er_path = er_path.replace(dir, ''); + er_message = er_message.replace(dir, ''); + } + } + + switch (er_message) { case 'emitted': assert.equal(er.domain, d); assert.equal(er.domain_emitter, e); @@ -60,14 +75,14 @@ d.on('error', function(er) { assert.equal(typeof er.domain_bound, 'function'); assert.ok(!er.domain_emitter); assert.equal(er.code, 'ENOENT'); - assert.equal(er.path, 'this file does not exist'); + assert.equal(er_path, 'this file does not exist'); assert.equal(typeof er.errno, 'number'); break; case "ENOENT, open 'stream for nonexistent file'": assert.equal(typeof er.errno, 'number'); assert.equal(er.code, 'ENOENT'); - assert.equal(er.path, 'stream for nonexistent file'); + assert.equal(er_path, 'stream for nonexistent file'); assert.equal(er.domain, d); assert.equal(er.domain_emitter, fst); assert.ok(!er.domain_bound); @@ -127,6 +142,13 @@ function fn(er) { var bound = d.intercept(fn); bound(new Error('bound')); +// intercepted should never pass first argument to callback +function fn2(data) { + assert.equal(data, 'data', 'should not be null err argument') +} + +var bound = d.intercept(fn2); +bound(null, 'data'); // throwing in a bound fn is also caught, @@ -192,6 +214,10 @@ d.run(function() { }); }); +var result = d.run(function () { + return 'return value'; +}); +assert.equal(result, 'return value'); var fst = fs.createReadStream('stream for nonexistent file') diff --git a/test/simple/test-eio-limit.js b/test/simple/test-eio-limit.js index 15f0bd03b22..5902db43933 100644 --- a/test/simple/test-eio-limit.js +++ b/test/simple/test-eio-limit.js @@ -27,7 +27,7 @@ var assert = require('assert'), function repeat(fn) { if (started != 0) { - assert.ok(started - done < 100); + assert.ok(started - done < 200); } process.nextTick(function() { diff --git a/test/simple/test-event-emitter-remove-all-listeners.js b/test/simple/test-event-emitter-remove-all-listeners.js index 6e27f3eb702..38cfb79c67e 100644 --- a/test/simple/test-event-emitter-remove-all-listeners.js +++ b/test/simple/test-event-emitter-remove-all-listeners.js @@ -39,10 +39,15 @@ e1.removeAllListeners('baz'); assert.deepEqual(e1.listeners('foo'), [listener]); assert.deepEqual(e1.listeners('bar'), []); assert.deepEqual(e1.listeners('baz'), []); -// identity check, the array should not change -assert.equal(e1.listeners('foo'), fooListeners); -assert.equal(e1.listeners('bar'), barListeners); -assert.equal(e1.listeners('baz'), bazListeners); +// after calling removeAllListeners, +// the old listeners array should stay unchanged +assert.deepEqual(fooListeners, [listener]); +assert.deepEqual(barListeners, [listener]); +assert.deepEqual(bazListeners, [listener, listener]); +// after calling removeAllListeners, +// new listeners arrays are different from the old +assert.notEqual(e1.listeners('bar'), barListeners); +assert.notEqual(e1.listeners('baz'), bazListeners); var e2 = new events.EventEmitter(); e2.on('foo', listener); diff --git a/test/simple/test-fs-readfile-pipe.js b/test/simple/test-fs-readfile-pipe.js new file mode 100644 index 00000000000..8ca165144ff --- /dev/null +++ b/test/simple/test-fs-readfile-pipe.js @@ -0,0 +1,55 @@ +// Copyright Joyent, Inc. and other Node 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. + +var common = require('../common'); +var assert = require('assert'); + +// simulate `cat readfile.js | node readfile.js` + +// TODO: Have some way to make this work on windows. +if (process.platform === 'win32') { + console.error('No /dev/stdin on windows. Skipping test.'); + process.exit(); +} + +var fs = require('fs'); + +var dataExpected = fs.readFileSync(__filename, 'utf8'); + +if (process.argv[2] === 'child') { + fs.readFile('/dev/stdin', function(er, data) { + if (er) throw er; + process.stdout.write(data); + }); + return; +} + +var exec = require('child_process').exec; +var f = JSON.stringify(__filename); +var node = JSON.stringify(process.execPath); +var cmd = 'cat ' + f + ' | ' + node + ' ' + f + ' child'; +exec(cmd, function(err, stdout, stderr) { + if (err) console.error(err); + assert(!err, 'it exits normally'); + assert(stdout === dataExpected, 'it reads the file and outputs it'); + assert(stderr === '', 'it does not write to stderr'); + console.log('ok'); +}); diff --git a/test/simple/test-fs-readfile-zero-byte-liar.js b/test/simple/test-fs-readfile-zero-byte-liar.js new file mode 100644 index 00000000000..60f41226f1b --- /dev/null +++ b/test/simple/test-fs-readfile-zero-byte-liar.js @@ -0,0 +1,58 @@ +// Copyright Joyent, Inc. and other Node 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. + +var common = require('../common'); +var assert = require('assert'); +var fs = require('fs'); + +var dataExpected = fs.readFileSync(__filename, 'utf8'); + +// sometimes stat returns size=0, but it's a lie. +fs._fstat = fs.fstat; +fs._fstatSync = fs.fstatSync; + +fs.fstat = function(fd, cb) { + fs._fstat(fd, function(er, st) { + if (er) return cb(er); + st.size = 0; + return cb(er, st); + }); +}; + +fs.fstatSync = function(fd) { + var st = fs._fstatSync; + st.size = 0; + return st; +}; + +var d = fs.readFileSync(__filename, 'utf8'); +assert.equal(d, dataExpected); + +var called = false; +fs.readFile(__filename, 'utf8', function (er, d) { + assert.equal(d, dataExpected); + called = true; +}); + +process.on('exit', function() { + assert(called); + console.log("ok"); +}); diff --git a/test/simple/test-fs-realpath.js b/test/simple/test-fs-realpath.js index b2c8e9b0109..2f126ea3004 100644 --- a/test/simple/test-fs-realpath.js +++ b/test/simple/test-fs-realpath.js @@ -19,41 +19,47 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE // USE OR OTHER DEALINGS IN THE SOFTWARE. - - - var common = require('../common'); var assert = require('assert'); var fs = require('fs'); var path = require('path'); var exec = require('child_process').exec; var async_completed = 0, async_expected = 0, unlink = []; +var isWindows = process.platform === 'win32'; +var skipSymlinks = false; + +var root = '/'; +if (isWindows) { + // something like "C:\\" + root = process.cwd().substr(0, 3); + + // On Windows, creating symlinks requires admin privileges. + // We'll only try to run symlink test if we have enough privileges. + try { + exec('whoami /priv', function(err, o) { + if (err || o.indexOf('SeCreateSymbolicLinkPrivilege') == -1) { + skipSymlinks = true; + } + runTest(); + }); + } catch (er) { + // better safe than sorry + skipSymlinks = true; + process.nextTick(runTest); + } +} else { + process.nextTick(runTest); +} + function tmp(p) { return path.join(common.tmpDir, p); } -var fixturesAbsDir; -var tmpAbsDir; -function getAbsPaths(cb) { - var failed = false; - var did = 0; - var expect = 2; - bashRealpath(common.fixturesDir, function(er, path) { - if (failed) return; - if (er) return cb(failed = er); - fixturesAbsDir = path; - did++; - if (did === expect) cb(); - }); - bashRealpath(common.tmpDir, function(er, path) { - if (failed) return; - if (er) return cb(failed = er); - tmpAbsDir = path; - did++; - if (did === expect) cb(); - }); -} +var fixturesAbsDir = common.fixturesDir; +var tmpAbsDir = common.tmpDir; + +console.error("absolutes\n%s\n%s", fixturesAbsDir, tmpAbsDir); function asynctest(testBlock, args, callback, assertBlock) { async_expected++; @@ -72,20 +78,15 @@ function asynctest(testBlock, args, callback, assertBlock) { })); } -function bashRealpath(path, callback) { - exec("cd '" + path.replace("'", "\\'") + "' && pwd -P", function(err, o) { - callback(err, o.trim()); - }); -} - // sub-tests: -function test_simple_error_callback() { +function test_simple_error_callback(cb) { var ncalls = 0; fs.realpath('/this/path/does/not/exist', function(err, s) { assert(err); assert(!s); ncalls++; + cb(); }); process.on('exit', function() { @@ -95,21 +96,26 @@ function test_simple_error_callback() { function test_simple_relative_symlink(callback) { console.log('test_simple_relative_symlink'); + if (skipSymlinks) { + console.log('skipping symlink test (no privs)'); + return runNextTest(); + } var entry = common.tmpDir + '/symlink', expected = common.tmpDir + '/cycles/root.js'; [ [entry, '../tmp/cycles/root.js'] ].forEach(function(t) { try {fs.unlinkSync(t[0]);}catch (e) {} - fs.symlinkSync(t[1], t[0]); + console.log('fs.symlinkSync(%j, %j, %j)', t[1], t[0], 'file'); + fs.symlinkSync(t[1], t[0], 'file'); unlink.push(t[0]); }); var result = fs.realpathSync(entry); - assert.equal(result, expected, + assert.equal(result, path.resolve(expected), 'got ' + common.inspect(result) + ' expected ' + common.inspect(expected)); asynctest(fs.realpath, [entry], callback, function(err, result) { - assert.equal(result, expected, + assert.equal(result, path.resolve(expected), 'got ' + common.inspect(result) + ' expected ' + @@ -119,23 +125,31 @@ function test_simple_relative_symlink(callback) { function test_simple_absolute_symlink(callback) { console.log('test_simple_absolute_symlink'); + + // this one should still run, even if skipSymlinks is set, + // because it uses a junction. + var type = skipSymlinks ? 'junction' : 'dir'; + + console.log('using type=%s', type); + var entry = tmpAbsDir + '/symlink', - expected = fixturesAbsDir + '/nested-index/one/index.js'; + expected = fixturesAbsDir + '/nested-index/one'; [ [entry, expected] ].forEach(function(t) { try {fs.unlinkSync(t[0]);} catch (e) {} - fs.symlinkSync(t[1], t[0]); + console.error('fs.symlinkSync(%j, %j, %j)', t[1], t[0], type); + fs.symlinkSync(t[1], t[0], type); unlink.push(t[0]); }); var result = fs.realpathSync(entry); - assert.equal(result, expected, + assert.equal(result, path.resolve(expected), 'got ' + common.inspect(result) + ' expected ' + common.inspect(expected)); asynctest(fs.realpath, [entry], callback, function(err, result) { - assert.equal(result, expected, + assert.equal(result, path.resolve(expected), 'got ' + common.inspect(result) + ' expected ' + @@ -145,61 +159,74 @@ function test_simple_absolute_symlink(callback) { function test_deep_relative_file_symlink(callback) { console.log('test_deep_relative_file_symlink'); + if (skipSymlinks) { + console.log('skipping symlink test (no privs)'); + return runNextTest(); + } + var expected = path.join(common.fixturesDir, 'cycles', 'root.js'); var linkData1 = '../../cycles/root.js'; var linkPath1 = path.join(common.fixturesDir, 'nested-index', 'one', 'symlink1.js'); try {fs.unlinkSync(linkPath1);} catch (e) {} - fs.symlinkSync(linkData1, linkPath1); + fs.symlinkSync(linkData1, linkPath1, 'file'); var linkData2 = '../one/symlink1.js'; var entry = path.join(common.fixturesDir, 'nested-index', 'two', 'symlink1-b.js'); try {fs.unlinkSync(entry);} catch (e) {} - fs.symlinkSync(linkData2, entry); + fs.symlinkSync(linkData2, entry, 'file'); unlink.push(linkPath1); unlink.push(entry); - assert.equal(fs.realpathSync(entry), expected); + assert.equal(fs.realpathSync(entry), path.resolve(expected)); asynctest(fs.realpath, [entry], callback, function(err, result) { - assert.equal(result, expected, + assert.equal(result, path.resolve(expected), 'got ' + common.inspect(result) + ' expected ' + - common.inspect(expected)); + common.inspect(path.resolve(expected))); }); } function test_deep_relative_dir_symlink(callback) { console.log('test_deep_relative_dir_symlink'); + if (skipSymlinks) { + console.log('skipping symlink test (no privs)'); + return runNextTest(); + } var expected = path.join(common.fixturesDir, 'cycles', 'folder'); var linkData1b = '../../cycles/folder'; var linkPath1b = path.join(common.fixturesDir, 'nested-index', 'one', 'symlink1-dir'); try {fs.unlinkSync(linkPath1b);} catch (e) {} - fs.symlinkSync(linkData1b, linkPath1b); + fs.symlinkSync(linkData1b, linkPath1b, 'dir'); var linkData2b = '../one/symlink1-dir'; var entry = path.join(common.fixturesDir, 'nested-index', 'two', 'symlink12-dir'); try {fs.unlinkSync(entry);} catch (e) {} - fs.symlinkSync(linkData2b, entry); + fs.symlinkSync(linkData2b, entry, 'dir'); unlink.push(linkPath1b); unlink.push(entry); - assert.equal(fs.realpathSync(entry), expected); + assert.equal(fs.realpathSync(entry), path.resolve(expected)); asynctest(fs.realpath, [entry], callback, function(err, result) { - assert.equal(result, expected, + assert.equal(result, path.resolve(expected), 'got ' + common.inspect(result) + ' expected ' + - common.inspect(expected)); + common.inspect(path.resolve(expected))); }); } function test_cyclic_link_protection(callback) { console.log('test_cyclic_link_protection'); + if (skipSymlinks) { + console.log('skipping symlink test (no privs)'); + return runNextTest(); + } var entry = common.tmpDir + '/cycles/realpath-3a'; [ [entry, '../cycles/realpath-3b'], @@ -207,7 +234,7 @@ function test_cyclic_link_protection(callback) { [common.tmpDir + '/cycles/realpath-3c', '../cycles/realpath-3a'] ].forEach(function(t) { try {fs.unlinkSync(t[0]);} catch (e) {} - fs.symlinkSync(t[1], t[0]); + fs.symlinkSync(t[1], t[0], 'dir'); unlink.push(t[0]); }); assert.throws(function() { fs.realpathSync(entry); }); @@ -219,6 +246,10 @@ function test_cyclic_link_protection(callback) { function test_cyclic_link_overprotection(callback) { console.log('test_cyclic_link_overprotection'); + if (skipSymlinks) { + console.log('skipping symlink test (no privs)'); + return runNextTest(); + } var cycles = common.tmpDir + '/cycles'; var expected = fs.realpathSync(cycles); var folder = cycles + '/folder'; @@ -226,19 +257,22 @@ function test_cyclic_link_overprotection(callback) { var testPath = cycles; for (var i = 0; i < 10; i++) testPath += '/folder/cycles'; try {fs.unlinkSync(link)} catch (ex) {} - fs.symlinkSync(cycles, link); + fs.symlinkSync(cycles, link, 'dir'); unlink.push(link); - assert.equal(fs.realpathSync(testPath), expected); + assert.equal(fs.realpathSync(testPath), path.resolve(expected)); asynctest(fs.realpath, [testPath], callback, function(er, res) { - assert.equal(res, expected); + assert.equal(res, path.resolve(expected)); }); } function test_relative_input_cwd(callback) { console.log('test_relative_input_cwd'); - var p = common.tmpDir.lastIndexOf('/'); - var entrydir = common.tmpDir.substr(0, p); - var entry = common.tmpDir.substr(p + 1) + '/cycles/realpath-3a'; + + // we need to get the relative path to the tmp dir from cwd. + // When the test runner is running it, that will be .../node/test + // but it's more common to run `./node test/.../`, so detect it here. + var entrydir = process.cwd(); + var entry = common.tmpDir.substr(entrydir.length + 1) + '/cycles/realpath-3a'; var expected = common.tmpDir + '/cycles/root.js'; [ [entry, '../cycles/realpath-3b'], @@ -246,30 +280,40 @@ function test_relative_input_cwd(callback) { [common.tmpDir + '/cycles/realpath-3c', 'root.js'] ].forEach(function(t) { var fn = t[0]; - if (fn.charAt(0) !== '/') fn = entrydir + '/' + fn; + console.error('fn=%j', fn); try {fs.unlinkSync(fn);} catch (e) {} - fs.symlinkSync(t[1], fn); + var b = path.basename(t[1]); + var type = (b === 'root.js' ? 'file' : 'dir'); + console.log('fs.symlinkSync(%j, %j, %j)', t[1], fn, type); + fs.symlinkSync(t[1], fn, 'file'); unlink.push(fn); }); + var origcwd = process.cwd(); process.chdir(entrydir); - assert.equal(fs.realpathSync(entry), expected); + assert.equal(fs.realpathSync(entry), path.resolve(expected)); asynctest(fs.realpath, [entry], callback, function(err, result) { process.chdir(origcwd); - assert.equal(result, expected, + assert.equal(result, path.resolve(expected), 'got ' + common.inspect(result) + ' expected ' + - common.inspect(expected)); + common.inspect(path.resolve(expected))); return true; }); } function test_deep_symlink_mix(callback) { console.log('test_deep_symlink_mix'); + if (isWindows) { + // This one is a mix of files and directories, and it's quite tricky + // to get the file/dir links sorted out correctly. + console.log('skipping symlink test (no way to work on windows)'); + return runNextTest(); + } + // todo: check to see that common.fixturesDir is not rooted in the // same directory as our test symlink. - // obtain our current realpath using bash (so we can test ourselves) /* /tmp/node-test-realpath-f1 -> ../tmp/node-test-realpath-d1/foo /tmp/node-test-realpath-d1 -> ../node-test-realpath-d2 @@ -306,33 +350,32 @@ function test_deep_symlink_mix(callback) { unlink.push(tmp('node-test-realpath-d2')); } var expected = tmpAbsDir + '/cycles/root.js'; - assert.equal(fs.realpathSync(entry), expected); + assert.equal(fs.realpathSync(entry), path.resolve(expected)); asynctest(fs.realpath, [entry], callback, function(err, result) { - assert.equal(result, expected, + assert.equal(result, path.resolve(expected), 'got ' + common.inspect(result) + ' expected ' + - common.inspect(expected)); + common.inspect(path.resolve(expected))); return true; }); } function test_non_symlinks(callback) { console.log('test_non_symlinks'); - var p = tmpAbsDir.lastIndexOf('/'); - var entrydir = tmpAbsDir.substr(0, p); - var entry = tmpAbsDir.substr(p + 1) + '/cycles/root.js'; + var entrydir = path.dirname(tmpAbsDir); + var entry = tmpAbsDir.substr(entrydir.length + 1) + '/cycles/root.js'; var expected = tmpAbsDir + '/cycles/root.js'; var origcwd = process.cwd(); process.chdir(entrydir); - assert.equal(fs.realpathSync(entry), expected); + assert.equal(fs.realpathSync(entry), path.resolve(expected)); asynctest(fs.realpath, [entry], callback, function(err, result) { process.chdir(origcwd); - assert.equal(result, expected, + assert.equal(result, path.resolve(expected), 'got ' + common.inspect(result) + ' expected ' + - common.inspect(expected)); + common.inspect(path.resolve(expected))); return true; }); } @@ -342,12 +385,53 @@ function test_escape_cwd(cb) { console.log('test_escape_cwd'); asynctest(fs.realpath, ['..'], cb, function(er, uponeActual) { assert.equal(upone, uponeActual, - 'realpath("..") expected: ' + upone + ' actual:' + uponeActual); + 'realpath("..") expected: ' + path.resolve(upone) + ' actual:' + uponeActual); }); } var uponeActual = fs.realpathSync('..'); assert.equal(upone, uponeActual, - 'realpathSync("..") expected: ' + upone + ' actual:' + uponeActual); + 'realpathSync("..") expected: ' + path.resolve(upone) + ' actual:' + uponeActual); + + +// going up with .. multiple times +// . +// `-- a/ +// |-- b/ +// | `-- e -> .. +// `-- d -> .. +// realpath(a/b/e/d/a/b/e/d/a) ==> a +function test_up_multiple(cb) { + console.error('test_up_multiple'); + if (skipSymlinks) { + console.log('skipping symlink test (no privs)'); + return runNextTest(); + } + fs.mkdirSync(tmp('a'), 0755); + fs.mkdirSync(tmp('a/b'), 0755); + fs.symlinkSync('..', tmp('a/d'), 'dir'); + unlink.push(tmp('a/d')); + fs.symlinkSync('..', tmp('a/b/e'), 'dir'); + unlink.push(tmp('a/b/e')); + + var abedabed = tmp('abedabed'.split('').join('/')); + var abedabed_real = tmp(''); + + var abedabeda = tmp('abedabeda'.split('').join('/')); + var abedabeda_real = tmp('a'); + + assert.equal(fs.realpathSync(abedabeda), abedabeda_real); + assert.equal(fs.realpathSync(abedabed), abedabed_real); + fs.realpath(abedabeda, function (er, real) { + if (er) throw er; + assert.equal(abedabeda_real, real); + fs.realpath(abedabed, function (er, real) { + if (er) throw er; + assert.equal(abedabed_real, real); + cb(); + }); + }); +} + // absolute symlinks with children. // . @@ -359,6 +443,13 @@ assert.equal(upone, uponeActual, // realpath(root+'/a/link/c/x.txt') ==> root+'/a/b/c/x.txt' function test_abs_with_kids(cb) { console.log('test_abs_with_kids'); + + // this one should still run, even if skipSymlinks is set, + // because it uses a junction. + var type = skipSymlinks ? 'junction' : 'dir'; + + console.log('using type=%s', type); + var root = tmpAbsDir + '/node-test-realpath-abs-kids'; function cleanup() { ['/a/b/c/x.txt', @@ -385,22 +476,24 @@ function test_abs_with_kids(cb) { fs.mkdirSync(root + folder, 0700); }); fs.writeFileSync(root + '/a/b/c/x.txt', 'foo'); - fs.symlinkSync(root + '/a/b', root + '/a/link'); + fs.symlinkSync(root + '/a/b', root + '/a/link', type); } setup(); var linkPath = root + '/a/link/c/x.txt'; var expectPath = root + '/a/b/c/x.txt'; var actual = fs.realpathSync(linkPath); // console.log({link:linkPath,expect:expectPath,actual:actual},'sync'); - assert.equal(actual, expectPath); + assert.equal(actual, path.resolve(expectPath)); asynctest(fs.realpath, [linkPath], cb, function(er, actual) { // console.log({link:linkPath,expect:expectPath,actual:actual},'async'); - assert.equal(actual, expectPath); + assert.equal(actual, path.resolve(expectPath)); cleanup(); }); } function test_lying_cache_liar(cb) { + var n = 2; + // this should not require *any* stat calls, since everything // checked by realpath will be found in the cache. console.log('test_lying_cache_liar'); @@ -410,18 +503,33 @@ function test_lying_cache_liar(cb) { '/a/b' : '/a/b', '/a/b/c' : '/a/b', '/a/b/d' : '/a/b/d' }; - var rps = fs.realpathSync('/foo/bar/baz/bluff', cache); - assert.equal(cache['/foo/bar/baz/bluff'], rps); - fs.realpath('/1/2/3/4/5/6/7', cache, function(er, rp) { - assert.equal(cache['/1/2/3/4/5/6/7'], rp); + if (isWindows) { + var wc = {}; + Object.keys(cache).forEach(function(k) { + wc[ path.resolve(k) ] = path.resolve(cache[k]); + }); + cache = wc; + } + + var bluff = path.resolve('/foo/bar/baz/bluff'); + var rps = fs.realpathSync(bluff, cache); + assert.equal(cache[bluff], rps); + var nums = path.resolve('/1/2/3/4/5/6/7'); + var called = false; // no sync cb calling! + fs.realpath(nums, cache, function(er, rp) { + called = true; + assert.equal(cache[nums], rp); + if (--n === 0) cb(); }); + assert(called === false); - var test = '/a/b/c/d', - expect = '/a/b/d'; + var test = path.resolve('/a/b/c/d'), + expect = path.resolve('/a/b/d'); var actual = fs.realpathSync(test, cache); assert.equal(expect, actual); fs.realpath(test, cache, function(er, actual) { assert.equal(expect, actual); + if (--n === 0) cb(); }); } @@ -440,18 +548,31 @@ var tests = [ test_non_symlinks, test_escape_cwd, test_abs_with_kids, - test_lying_cache_liar + test_lying_cache_liar, + test_up_multiple ]; var numtests = tests.length; +var testsRun = 0; function runNextTest(err) { if (err) throw err; var test = tests.shift(); - if (!test) console.log(numtests + - ' subtests completed OK for fs.realpath'); - else test(runNextTest); + if (!test) { + return console.log(numtests + + ' subtests completed OK for fs.realpath'); + } + testsRun++; + test(runNextTest); } -getAbsPaths(function(er) { - if (er) throw er; + + +assert.equal(root, fs.realpathSync('/')); +fs.realpath('/', function(err, result) { + assert.equal(null, err); + assert.equal(root, result); +}); + + +function runTest() { var tmpDirs = ['cycles', 'cycles/folder']; tmpDirs.forEach(function(t) { t = tmp(t); @@ -461,19 +582,13 @@ getAbsPaths(function(er) { fs.mkdirSync(t, 0700); }); fs.writeFileSync(tmp('cycles/root.js'), "console.error('roooot!');"); + console.error('start tests'); runNextTest(); -}); - - -assert.equal('/', fs.realpathSync('/')); -fs.realpath('/', function(err, result) { - assert.equal(null, err); - assert.equal('/', result); -}); - +} process.on('exit', function() { + assert.equal(numtests, testsRun); unlink.forEach(function(path) { try {fs.unlinkSync(path);} catch (e) {} }); assert.equal(async_completed, async_expected); }); diff --git a/test/simple/test-fs-stat.js b/test/simple/test-fs-stat.js index 40782029b6d..90b0ba52d4a 100644 --- a/test/simple/test-fs-stat.js +++ b/test/simple/test-fs-stat.js @@ -19,9 +19,6 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE // USE OR OTHER DEALINGS IN THE SOFTWARE. - - - var common = require('../common'); var assert = require('assert'); var fs = require('fs'); @@ -36,6 +33,7 @@ fs.stat('.', function(err, stats) { assert.ok(stats.mtime instanceof Date); success_count++; } + assert(this === global); }); fs.lstat('.', function(err, stats) { @@ -46,6 +44,7 @@ fs.lstat('.', function(err, stats) { assert.ok(stats.mtime instanceof Date); success_count++; } + assert(this === global); }); // fstat @@ -62,7 +61,10 @@ fs.open('.', 'r', undefined, function(err, fd) { success_count++; fs.close(fd); } + assert(this === global); }); + + assert(this === global); }); // fstatSync diff --git a/test/simple/test-http-full-response.js b/test/simple/test-http-full-response.js index 832c046e2c4..d33df8b883c 100644 --- a/test/simple/test-http-full-response.js +++ b/test/simple/test-http-full-response.js @@ -49,8 +49,8 @@ function runAb(opts, callback) { var command = 'ab ' + opts + ' http://127.0.0.1:' + common.PORT + '/'; exec(command, function(err, stdout, stderr) { if (err) { - if (stderr.indexOf('ab') >= 0) { - console.log('ab not installed? skipping test.\n' + stderr); + if (/ab|apr/mi.test(stderr)) { + console.log('problem spawning ab - skipping test.\n' + stderr); process.reallyExit(0); } process.exit(); diff --git a/test/simple/test-http-get-pipeline-problem.js b/test/simple/test-http-get-pipeline-problem.js index 1074adb4a78..720ce4b89c8 100644 --- a/test/simple/test-http-get-pipeline-problem.js +++ b/test/simple/test-http-get-pipeline-problem.js @@ -24,7 +24,7 @@ // We are demonstrating a problem with http.get when queueing up many // transfers. The server simply introduces some delay and sends a file. -// Note this is demonstarted with connection: close. +// Note this is demonstrated with connection: close. var common = require('../common'); var assert = require('assert'); var http = require('http'); @@ -89,7 +89,7 @@ var checkedFiles = false; function checkFiles() { // Should see 1.jpg, 2.jpg, ..., 100.jpg in tmpDir var files = fs.readdirSync(common.tmpDir); - assert.equal(total, files.length); + assert(total <= files.length); for (var i = 0; i < total; i++) { var fn = i + '.jpg'; diff --git a/test/simple/test-listen-fd-cluster.js b/test/simple/test-listen-fd-cluster.js new file mode 100644 index 00000000000..0d6d7748aa1 --- /dev/null +++ b/test/simple/test-listen-fd-cluster.js @@ -0,0 +1,136 @@ +// Copyright Joyent, Inc. and other Node 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. + +var common = require('../common'); +var assert = require('assert'); +var http = require('http'); +var net = require('net'); +var PORT = common.PORT; +var spawn = require('child_process').spawn; +var cluster = require('cluster'); + +console.error('Cluster listen fd test', process.argv.slice(2)); + +if (process.platform === 'win32') { + console.error('This test is disabled on windows.'); + return; +} + +switch (process.argv[2]) { + case 'master': return master(); + case 'worker': return worker(); + case 'parent': return parent(); + default: return test(); +} + +// spawn the parent, and listen for it to tell us the pid of the cluster. +// WARNING: This is an example of listening on some arbitrary FD number +// that has already been bound elsewhere in advance. However, binding +// server handles to stdio fd's is NOT a good or reliable way to do +// concurrency in HTTP servers! Use the cluster module, or if you want +// a more low-level approach, use child process IPC manually. +function test() { + var parent = spawn(process.execPath, [__filename, 'parent'], { + stdio: [ 0, 'pipe', 2 ] + }); + var json = ''; + parent.stdout.on('data', function(c) { + json += c.toString(); + if (json.indexOf('\n') !== -1) next(); + }); + function next() { + console.error('output from parent = %s', json); + var cluster = JSON.parse(json); + // now make sure that we can request to the worker, then kill it. + http.get({ + server: 'localhost', + port: PORT, + path: '/', + }).on('response', function (res) { + var s = ''; + res.on('data', function(c) { + s += c.toString(); + }); + res.on('end', function() { + // kill the worker before we start doing asserts. + // it's really annoying when tests leave orphans! + parent.kill(); + process.kill(cluster.master, 'SIGKILL'); + + assert.equal(s, 'hello from worker\n'); + assert.equal(res.statusCode, 200); + console.log('ok'); + }); + }) + } +} + +function parent() { + console.error('about to listen in parent'); + var server = net.createServer(function(conn) { + console.error('connection on parent'); + conn.end('hello from parent\n'); + }).listen(PORT, function() { + console.error('server listening on %d', PORT); + + var spawn = require('child_process').spawn; + var master = spawn(process.execPath, [__filename, 'master'], { + stdio: [ 0, 1, 2, server._handle ], + detached: true + }); + + // Now close the parent, so that the master is the only thing + // referencing that handle. Note that connections will still + // be accepted, because the master has the fd open. + server.close(); + + master.on('exit', function(code) { + console.error('master exited', code); + }); + + master.on('close', function() { + console.error('master closed'); + }); + console.error('master spawned'); + }); +} + +function master() { + console.error('in master, spawning worker'); + cluster.setupMaster({ + args: [ 'worker' ] + }); + var worker = cluster.fork(); + console.log('%j\n', { master: process.pid, worker: worker.pid }); +} + + +function worker() { + console.error('worker, about to create server and listen on fd=3'); + // start a server on fd=3 + http.createServer(function(req, res) { + console.error('request on worker'); + console.error('%s %s', req.method, req.url, req.headers); + res.end('hello from worker\n'); + }).listen({ fd: 3 }, function() { + console.error('worker listening on fd=3'); + }); +} diff --git a/test/simple/test-listen-fd-detached-inherit.js b/test/simple/test-listen-fd-detached-inherit.js new file mode 100644 index 00000000000..dabc46cd313 --- /dev/null +++ b/test/simple/test-listen-fd-detached-inherit.js @@ -0,0 +1,119 @@ +// Copyright Joyent, Inc. and other Node 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. + +var common = require('../common'); +var assert = require('assert'); +var http = require('http'); +var net = require('net'); +var PORT = common.PORT; +var spawn = require('child_process').spawn; + +if (process.platform === 'win32') { + console.error('This test is disabled on windows.'); + return; +} + +switch (process.argv[2]) { + case 'child': return child(); + case 'parent': return parent(); + default: return test(); +} + +// spawn the parent, and listen for it to tell us the pid of the child. +// WARNING: This is an example of listening on some arbitrary FD number +// that has already been bound elsewhere in advance. However, binding +// server handles to stdio fd's is NOT a good or reliable way to do +// concurrency in HTTP servers! Use the cluster module, or if you want +// a more low-level approach, use child process IPC manually. +function test() { + var parent = spawn(process.execPath, [__filename, 'parent'], { + stdio: [ 0, 'pipe', 2 ] + }); + var json = ''; + parent.stdout.on('data', function(c) { + json += c.toString(); + if (json.indexOf('\n') !== -1) next(); + }); + function next() { + console.error('output from parent = %s', json); + var child = JSON.parse(json); + // now make sure that we can request to the child, then kill it. + http.get({ + server: 'localhost', + port: PORT, + path: '/', + }).on('response', function (res) { + var s = ''; + res.on('data', function(c) { + s += c.toString(); + }); + res.on('end', function() { + // kill the child before we start doing asserts. + // it's really annoying when tests leave orphans! + process.kill(child.pid, 'SIGKILL'); + try { + parent.kill(); + } catch (e) {} + + assert.equal(s, 'hello from child\n'); + assert.equal(res.statusCode, 200); + }); + }) + } +} + +// Listen on PORT, and then pass the handle to the detached child. +// Then output the child's pid, and immediately exit. +function parent() { + var server = net.createServer(function(conn) { + throw new Error('Should not see connections on parent'); + conn.end('HTTP/1.1 403 Forbidden\r\n\r\nI got problems.\r\n'); + }).listen(PORT, function() { + console.error('server listening on %d', PORT); + + var child = spawn(process.execPath, [__filename, 'child'], { + stdio: [ 0, 1, 2, server._handle ], + detached: true + }); + + console.log('%j\n', { pid: child.pid }); + + // Now close the parent, so that the child is the only thing + // referencing that handle. Note that connections will still + // be accepted, because the child has the fd open, but the parent + // will exit gracefully. + server.close(); + child.unref(); + }); +} + +// Run as a child of the parent() mode. +function child() { + // start a server on fd=3 + http.createServer(function(req, res) { + console.error('request on child'); + console.error('%s %s', req.method, req.url, req.headers); + res.end('hello from child\n'); + }).listen({ fd: 3 }, function() { + console.error('child listening on fd=3'); + }); +} + diff --git a/test/simple/test-listen-fd-detached.js b/test/simple/test-listen-fd-detached.js new file mode 100644 index 00000000000..3d98abeacda --- /dev/null +++ b/test/simple/test-listen-fd-detached.js @@ -0,0 +1,117 @@ +// Copyright Joyent, Inc. and other Node 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. + +var common = require('../common'); +var assert = require('assert'); +var http = require('http'); +var net = require('net'); +var PORT = common.PORT; +var spawn = require('child_process').spawn; + +if (process.platform === 'win32') { + console.error('This test is disabled on windows.'); + return; +} + +switch (process.argv[2]) { + case 'child': return child(); + case 'parent': return parent(); + default: return test(); +} + +// spawn the parent, and listen for it to tell us the pid of the child. +// WARNING: This is an example of listening on some arbitrary FD number +// that has already been bound elsewhere in advance. However, binding +// server handles to stdio fd's is NOT a good or reliable way to do +// concurrency in HTTP servers! Use the cluster module, or if you want +// a more low-level approach, use child process IPC manually. +function test() { + var parent = spawn(process.execPath, [__filename, 'parent'], { + stdio: [ 0, 'pipe', 2 ] + }); + var json = ''; + parent.stdout.on('data', function(c) { + json += c.toString(); + if (json.indexOf('\n') !== -1) next(); + }); + function next() { + console.error('output from parent = %s', json); + var child = JSON.parse(json); + // now make sure that we can request to the child, then kill it. + http.get({ + server: 'localhost', + port: PORT, + path: '/', + }).on('response', function (res) { + var s = ''; + res.on('data', function(c) { + s += c.toString(); + }); + res.on('end', function() { + // kill the child before we start doing asserts. + // it's really annoying when tests leave orphans! + process.kill(child.pid, 'SIGKILL'); + try { + parent.kill(); + } catch (e) {} + + assert.equal(s, 'hello from child\n'); + assert.equal(res.statusCode, 200); + }); + }) + } +} + +function parent() { + var server = net.createServer(function(conn) { + console.error('connection on parent'); + conn.end('hello from parent\n'); + }).listen(PORT, function() { + console.error('server listening on %d', PORT); + + var spawn = require('child_process').spawn; + var child = spawn(process.execPath, [__filename, 'child'], { + stdio: [ 'ignore', 'ignore', 'ignore', server._handle ], + detached: true + }); + + console.log('%j\n', { pid: child.pid }); + + // Now close the parent, so that the child is the only thing + // referencing that handle. Note that connections will still + // be accepted, because the child has the fd open, but the parent + // will exit gracefully. + server.close(); + child.unref(); + }); +} + +function child() { + // start a server on fd=3 + http.createServer(function(req, res) { + console.error('request on child'); + console.error('%s %s', req.method, req.url, req.headers); + res.end('hello from child\n'); + }).listen({ fd: 3 }, function() { + console.error('child listening on fd=3'); + }); +} + diff --git a/test/simple/test-listen-fd-server.js b/test/simple/test-listen-fd-server.js new file mode 100644 index 00000000000..8f3454fbbd6 --- /dev/null +++ b/test/simple/test-listen-fd-server.js @@ -0,0 +1,122 @@ +// Copyright Joyent, Inc. and other Node 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. + +var common = require('../common'); +var assert = require('assert'); +var http = require('http'); +var net = require('net'); +var PORT = common.PORT; +var spawn = require('child_process').spawn; + +if (process.platform === 'win32') { + console.error('This test is disabled on windows.'); + return; +} + +switch (process.argv[2]) { + case 'child': return child(); + case 'parent': return parent(); + default: return test(); +} + +// spawn the parent, and listen for it to tell us the pid of the child. +// WARNING: This is an example of listening on some arbitrary FD number +// that has already been bound elsewhere in advance. However, binding +// server handles to stdio fd's is NOT a good or reliable way to do +// concurrency in HTTP servers! Use the cluster module, or if you want +// a more low-level approach, use child process IPC manually. +function test() { + var parent = spawn(process.execPath, [__filename, 'parent'], { + stdio: [ 0, 'pipe', 2 ] + }); + var json = ''; + parent.stdout.on('data', function(c) { + json += c.toString(); + if (json.indexOf('\n') !== -1) next(); + }); + function next() { + console.error('output from parent = %s', json); + var child = JSON.parse(json); + // now make sure that we can request to the child, then kill it. + http.get({ + server: 'localhost', + port: PORT, + path: '/', + }).on('response', function (res) { + var s = ''; + res.on('data', function(c) { + s += c.toString(); + }); + res.on('end', function() { + // kill the child before we start doing asserts. + // it's really annoying when tests leave orphans! + process.kill(child.pid, 'SIGKILL'); + try { + parent.kill(); + } catch (e) {} + + assert.equal(s, 'hello from child\n'); + assert.equal(res.statusCode, 200); + }); + }) + } +} + +function child() { + // start a server on fd=3 + http.createServer(function(req, res) { + console.error('request on child'); + console.error('%s %s', req.method, req.url, req.headers); + res.end('hello from child\n'); + }).listen({ fd: 3 }, function() { + console.error('child listening on fd=3'); + }); +} + +function parent() { + var server = net.createServer(function(conn) { + console.error('connection on parent'); + conn.end('hello from parent\n'); + }).listen(PORT, function() { + console.error('server listening on %d', PORT); + + var spawn = require('child_process').spawn; + var child = spawn(process.execPath, [__filename, 'child'], { + stdio: [ 0, 1, 2, server._handle ] + }); + + console.log('%j\n', { pid: child.pid }); + + // Now close the parent, so that the child is the only thing + // referencing that handle. Note that connections will still + // be accepted, because the child has the fd open. + server.close(); + + child.on('exit', function(code) { + console.error('child exited', code); + }); + + child.on('close', function() { + console.error('child closed'); + }); + console.error('child spawned'); + }); +} diff --git a/test/simple/test-module-loading.js b/test/simple/test-module-loading.js index 3a90fe8b688..eadd6679c61 100644 --- a/test/simple/test-module-loading.js +++ b/test/simple/test-module-loading.js @@ -211,7 +211,8 @@ assert.deepEqual(json, { // the appropriate children, and so on. var children = module.children.reduce(function red(set, child) { - var id = path.relative(path.dirname(__dirname), child.id); + var id = path.relative(path.dirname(__dirname), child.id) + id = id.replace(/\\/g, '/'); set[id] = child.children.reduce(red, {}); return set; }, {}); diff --git a/test/simple/test-net-during-close.js b/test/simple/test-net-during-close.js new file mode 100644 index 00000000000..0bcdd4d3a0b --- /dev/null +++ b/test/simple/test-net-during-close.js @@ -0,0 +1,47 @@ +// Copyright Joyent, Inc. and other Node 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. + +var common = require('../common'); +var assert = require('assert'); +var net = require('net'); +var accessedProperties = false; + +var server = net.createServer(function(socket) { + socket.end(); +}); + +server.listen(common.PORT, function() { + var client = net.createConnection(common.PORT); + server.close(); + // server connection event has not yet fired + // client is still attempting to connect + assert.doesNotThrow(function() { + client.remoteAddress; + client.remotePort; + }); + accessedProperties = true; + // exit now, do not wait for the client error event + process.exit(0); +}); + +process.on('exit', function() { + assert(accessedProperties); +}); diff --git a/test/simple/test-net-socket-pause-resume-immediate.js b/test/simple/test-net-socket-pause-resume-immediate.js new file mode 100644 index 00000000000..0622d071a75 --- /dev/null +++ b/test/simple/test-net-socket-pause-resume-immediate.js @@ -0,0 +1,30 @@ +// Copyright Joyent, Inc. and other Node 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. + +var common = require('../common'); +var assert = require('assert'); +var net = require('net'); + +var sock = net.connect(1234, 'localhost'); +sock.pause(); +sock.resume(); +console.log('ok'); +process.exit(0); diff --git a/test/simple/test-net-write-slow.js b/test/simple/test-net-write-slow.js index 1297193ef97..468c311c5c8 100644 --- a/test/simple/test-net-write-slow.js +++ b/test/simple/test-net-write-slow.js @@ -32,7 +32,7 @@ buf.fill(0x61); // 'a' var server = net.createServer(function(socket) { socket.setNoDelay(); - socket.setTimeout(200); + socket.setTimeout(1000); socket.on('timeout', function() { assert.fail('flushed: ' + flushed + ', received: ' + received + '/' + SIZE * N); diff --git a/test/simple/test-os.js b/test/simple/test-os.js index a70142f9f7b..b141f000893 100644 --- a/test/simple/test-os.js +++ b/test/simple/test-os.js @@ -27,6 +27,18 @@ var assert = require('assert'); var os = require('os'); +process.env.TMPDIR = '/tmpdir'; +process.env.TMP = '/tmp'; +process.env.TEMP = '/temp'; +var t = ( process.platform === 'win32' ? 'c:\\windows\\temp' : '/tmp' ); +assert.equal(os.tmpDir(), '/tmpdir'); +process.env.TMPDIR = ''; +assert.equal(os.tmpDir(), '/tmp'); +process.env.TMP = ''; +assert.equal(os.tmpDir(), '/temp'); +process.env.TEMP = ''; +assert.equal(os.tmpDir(), t); + var hostname = os.hostname(); console.log('hostname = %s', hostname); assert.ok(hostname.length > 0); diff --git a/test/simple/test-process-env.js b/test/simple/test-process-env.js index fdf35ba7727..919d0d54ed4 100644 --- a/test/simple/test-process-env.js +++ b/test/simple/test-process-env.js @@ -47,8 +47,18 @@ if (process.argv[2] == 'you-are-the-child') { // failed assertion results in process exiting with status code 1 assert.equal(false, 'NODE_PROCESS_ENV_DELETED' in process.env); assert.equal(42, process.env.NODE_PROCESS_ENV); + assert.equal('asdf', process.env.hasOwnProperty); + var hasOwnProperty = Object.prototype.hasOwnProperty; + var has = hasOwnProperty.call(process.env, 'hasOwnProperty'); + assert.equal(true, has); process.exit(0); } else { + assert.equal(Object.prototype.hasOwnProperty, process.env.hasOwnProperty); + var has = process.env.hasOwnProperty('hasOwnProperty'); + assert.equal(false, has); + + process.env.hasOwnProperty = 'asdf'; + process.env.NODE_PROCESS_ENV = 42; assert.equal(42, process.env.NODE_PROCESS_ENV); diff --git a/test/simple/test-punycode.js b/test/simple/test-punycode.js index f3d6dd78192..fa6a9c0ec96 100644 --- a/test/simple/test-punycode.js +++ b/test/simple/test-punycode.js @@ -179,4 +179,17 @@ for (var encoded in tests) { } } +// BMP code point +assert.equal(punycode.ucs2.encode([0x61]), 'a'); +// supplementary code point (surrogate pair) +assert.equal(punycode.ucs2.encode([0x1D306]), '\uD834\uDF06'); +// high surrogate +assert.equal(punycode.ucs2.encode([0xD800]), '\uD800'); +// high surrogate followed by non-surrogates +assert.equal(punycode.ucs2.encode([0xD800, 0x61, 0x62]), '\uD800ab'); +// low surrogate +assert.equal(punycode.ucs2.encode([0xDC00]), '\uDC00'); +// low surrogate followed by non-surrogates +assert.equal(punycode.ucs2.encode([0xDC00, 0x61, 0x62]), '\uDC00ab'); + assert.equal(errors, 0); diff --git a/test/simple/test-regress-GH-1697.js b/test/simple/test-regress-GH-1697.js index 18790d483af..82aed3ec8ac 100644 --- a/test/simple/test-regress-GH-1697.js +++ b/test/simple/test-regress-GH-1697.js @@ -36,9 +36,11 @@ if (process.argv[2] === 'server') { server.close(); }); }); - server.listen(1234, '127.0.0.1'); - console.log('Server running.'); + server.listen(1234, '127.0.0.1', function() { + console.log('Server running.'); + }); + } else { // Client diff --git a/test/simple/test-regress-GH-3542.js b/test/simple/test-regress-GH-3542.js new file mode 100644 index 00000000000..90e0b78501a --- /dev/null +++ b/test/simple/test-regress-GH-3542.js @@ -0,0 +1,54 @@ +// Copyright Joyent, Inc. and other Node 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. + +// This test is only relevant on Windows. +if (process.platform !== 'win32') { + return process.exit(0); +} + +var common = require('../common.js'), + assert = require('assert'), + fs = require('fs'), + path = require('path'), + succeeded = 0; + +function test(p) { + var result = fs.realpathSync(p); + assert.strictEqual(result, path.resolve(p)); + + fs.realpath(p, function(err, result) { + assert.ok(!err); + assert.strictEqual(result, path.resolve(p)); + succeeded++; + }); +} + +test('//localhost/c$/windows/system32'); +test('//localhost/c$/windows'); +test('//localhost/c$/') +test('\\\\localhost\\c$') +test('c:\\'); +test('c:'); +test(process.env.windir); + +process.on('exit', function() { + assert.strictEqual(succeeded, 7); +}); \ No newline at end of file diff --git a/test/simple/test-repl.js b/test/simple/test-repl.js index d61a8231dc0..ae20a19f09e 100644 --- a/test/simple/test-repl.js +++ b/test/simple/test-repl.js @@ -30,6 +30,10 @@ var net = require('net'), prompt_unix = 'node via Unix socket> ', prompt_tcp = 'node via TCP socket> ', prompt_multiline = '... ', + prompt_npm = 'npm should be run outside of the ' + + 'node repl, in your normal shell.\n' + + '(Press Control-D to exit.)\n', + expect_npm = prompt_npm + prompt_unix, server_tcp, server_unix, client_tcp, client_unix, timer; @@ -76,8 +80,11 @@ function error_test() { JSON.stringify(client_unix.expect))); if (read_buffer.indexOf(prompt_unix) !== -1) { - assert.ok(read_buffer.match(client_unix.expect)); - common.error('match'); + // if it's an exact match, then don't do the regexp + if (read_buffer !== client_unix.expect) { + assert.ok(read_buffer.match(client_unix.expect)); + common.error('match'); + } read_buffer = ''; if (client_unix.list && client_unix.list.length > 0) { send_expect(client_unix.list); @@ -140,7 +147,10 @@ function error_test() { { client: client_unix, send: 'return 1;', expect: prompt_multiline }, { client: client_unix, send: '})()', - expect: '1' } + expect: '1' }, + // npm prompt error message + { client: client_unix, send: 'npm install foobar', + expect: expect_npm } ]); } diff --git a/test/simple/test-stdin-pause-resume-sync.js b/test/simple/test-stdin-pause-resume-sync.js new file mode 100644 index 00000000000..0e202a3063f --- /dev/null +++ b/test/simple/test-stdin-pause-resume-sync.js @@ -0,0 +1,31 @@ +// Copyright Joyent, Inc. and other Node 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. + +console.error('before opening stdin'); +process.stdin.resume(); +console.error('stdin opened'); +console.error('pausing stdin'); +process.stdin.pause(); +console.error('opening again'); +process.stdin.resume(); +console.error('pausing again'); +process.stdin.pause(); +console.error('should exit now'); diff --git a/test/simple/test-stdin-pipe-resume.js b/test/simple/test-stdin-pipe-resume.js new file mode 100644 index 00000000000..163d8369c9e --- /dev/null +++ b/test/simple/test-stdin-pipe-resume.js @@ -0,0 +1,48 @@ +// Copyright Joyent, Inc. and other Node 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. + +// This tests that piping stdin will cause it to resume() as well. +var common = require('../common'); +var assert = require('assert'); + +if (process.argv[2] === 'child') { + process.stdin.pipe(process.stdout); +} else { + var spawn = require('child_process').spawn; + var buffers = []; + var child = spawn(process.execPath, [__filename, 'child']); + child.stdout.on('data', function(c) { + buffers.push(c); + }); + child.stdout.on('close', function() { + var b = Buffer.concat(buffers).toString(); + assert.equal(b, 'Hello, world\n'); + console.log('ok'); + }); + child.stdin.write('Hel'); + child.stdin.write('lo,'); + child.stdin.write(' wo'); + setTimeout(function() { + child.stdin.write('rld\n'); + child.stdin.end(); + }, 10); +} + diff --git a/test/simple/test-tls-set-ciphers.js b/test/simple/test-tls-set-ciphers.js index 576094dcb73..a473a1d2678 100644 --- a/test/simple/test-tls-set-ciphers.js +++ b/test/simple/test-tls-set-ciphers.js @@ -33,7 +33,7 @@ if (process.platform === 'win32') { var options = { key: fs.readFileSync(common.fixturesDir + '/keys/agent2-key.pem'), cert: fs.readFileSync(common.fixturesDir + '/keys/agent2-cert.pem'), - ciphers: 'NULL-MD5' // it's ultra-fast! + ciphers: 'RC4-MD5' }; var reply = 'I AM THE WALRUS'; // something recognizable @@ -51,8 +51,8 @@ var server = tls.createServer(options, function(conn) { }); server.listen(common.PORT, '127.0.0.1', function() { - var cmd = 'openssl s_client -cipher NULL-MD5 -connect 127.0.0.1:' + - common.PORT; + var cmd = 'openssl s_client -cipher ' + options.ciphers + + ' -connect 127.0.0.1:' + common.PORT; exec(cmd, function(err, stdout, stderr) { if (err) throw err; diff --git a/tools/blog/README.md b/tools/blog/README.md new file mode 100644 index 00000000000..52a3be7fd23 --- /dev/null +++ b/tools/blog/README.md @@ -0,0 +1,5 @@ +# node-blog-gen + +Generates the node blog from the markdown files in doc/blog/. + + diff --git a/tools/blog/generate.js b/tools/blog/generate.js new file mode 100644 index 00000000000..8a310fac155 --- /dev/null +++ b/tools/blog/generate.js @@ -0,0 +1,283 @@ +#!/usr/bin/env node +var fs = require('fs'); +var marked = require('marked'); +var mkdirp = require('mkdirp'); +var glob = require('glob'); +var ejs = require('ejs'); +var path = require('path'); +var semver = require('semver'); + +var input = path.resolve(process.argv[2]); +var output = path.resolve(process.argv[3]); +var template = path.resolve(process.argv[4]); +var rssTemplate = path.resolve(process.argv[5]); + +var config = { + postsPerPage: 4 +}; + +console.error("argv=%j", process.argv) + +fs.readFile(template, 'utf8', function(er, contents) { + if (er) throw er; + template = ejs.compile(contents, template); + template.filename = 'index.html'; + fs.readFile(rssTemplate, 'utf8', function(er, contents) { + if (er) throw er; + rssTemplate = ejs.compile(contents, rssTemplate); + rssTemplate.filename = 'index.xml'; + readInput(); + }); +}); + +function readInput() { + glob(input + '/**/*.md', function(er, files) { + if (er) throw er; + readFiles(files); + }); +} + +function readFiles(files) { + var n = files.length; + var data = { files: {}, feeds: {}, posts: {}}; + + files.forEach(function(file) { + fs.readFile(file, 'utf8', next(file)); + }); + + function next(file) { return function(er, contents) { + if (er) throw er; + if (contents) { + contents = parseFile(file, contents); + if (contents) { + data.files[file] = contents + } + } + if (--n === 0) { + buildOutput(data); + } + }} +} + +function parseFile(file, contents) { + var c = contents.split('\n\n'); + var head = c.shift(); + c = c.join('\n\n'); + var post = head.split('\n').reduce(function(set, kv) { + kv = kv.split(':'); + var key = kv.shift().trim(); + var val = kv.join(':').trim(); + set[key] = val; + return set; + }, {}); + if (post.status && post.status !== 'publish') return null; + post.body = c; + post.src = file; + return post; +} + +function buildPermalinks(data) { + Object.keys(data.files).forEach(function(k) { + data.posts[k] = buildPermalink(k, data.files[k]); + }); +} + +function buildPermalink(key, post) { + var data = {}; + data.pageid = post.slug; + data.title = post.title; + data.content = post.content = marked.parse(post.body); + + // Fix for chjj/marked#56 + data.content = post.content = data.content + .replace(/\1<\/a>/g, '$1'); + + data.post = post; + + if (!post.date) throw new Error('post date is required ' + post.src); + else post.date = new Date(post.date); + var d = post.date; + + var y = d.getYear() + 1900; + var m = d.getMonth() + 1; + if (m < 10) m = '0' + m; + var d = d.getDate(); + if (d < 10) d = '0' + d; + var uri = '/' + y + '/' + m + '/' + d + '/' + post.slug + '/'; + post.data = data; + post.uri = uri; + + post.permalink = data.permalink = uri; + return data; +} + +function writeFile(uri, data, templ) { + if (!templ) templ = template; + data.uri = path.join(data.uri); + uri = path.join(uri); + var contents = templ(data); + var outdir = path.join(output, uri); + mkdirp(outdir, function(er) { + if (er) throw er; + var file = path.resolve(outdir, templ.filename); + fs.writeFile(file, contents, 'utf8', function(er) { + if (er) throw er; + console.log('wrote: ', data.pageid, path.relative(process.cwd(), file)); + }); + }); +} + +// sort in reverse chronological order +// prune out any releases that are not the most recent on their branch. +function buildFeeds(data) { + // first, sort by date. + var posts = Object.keys(data.posts).map(function(k) { + return data.posts[k].post; + }).sort(function(a, b) { + a = a.date.getTime(); + b = b.date.getTime(); + return (a === b) ? 0 : a > b ? -1 : 1; + }) + + // separate release posts by release families. + var releases = posts.reduce(function(releases, post) { + if (post.category !== 'release') return releases; + var ver = semver.parse(post.version); + if (!ver) return; + var major = +ver[1]; + var minor = +ver[2]; + var patch = +ver[3]; + var family = [major, minor]; + ver = [major, minor, patch, post]; + if (family[1] % 2) family[1]++; + family = family.join('.'); + post.family = family; + releases[family] = releases[family] || []; + releases[family].push(post); + return releases; + }, {}); + + // separate by categories. + var categories = posts.reduce(function(categories, post) { + if (!post.category) return categories; + if (!categories[post.category]) { + categories[post.category] = []; + } + categories[post.category].push(post); + return categories; + }, {}); + + // paginate categories. + for (var cat in categories) { + categories[cat] = paginate(categories[cat], cat); + } + + // filter non-latest release notices out of main feeds. + // still show the first stable release of the family, since + // it usually is an important milestone with benchmarks and stuff. + var main = posts.filter(function(post) { + if (post.version && post.family) { + var ver = semver.parse(post.version) + if (+ver[2] % 2 === 0 && +ver[3] === 0) { + // 0.x.0, where x is event + return true; + } + if (post.version && post.family && post !== releases[post.family][0]) { + return false; + } + } + return true; + }); + + // add previous/next based on main feed. + main.forEach(function (post, i, posts) { + post.next = posts[i - 1]; + post.prev = posts[i + 1]; + }) + + // paginate each feed. + main = paginate(main, ''); + + // put previous/next links on orphaned old releases so you can get back + for (var family in releases) { + releases[family].forEach(function(post, i, family) { + if (!post.next) post.next = family[i - 1]; + if (!post.next) post.next = family[0].next; + // if (!post.next) post.next = family[0]; + + if (!post.prev) post.prev = family[i + 1]; + if (!post.prev) post.prev = family[0].prev; + }); + // paginate + releases[family] = paginate(releases[family], 'release-' + family); + } + + // paginate + data.feeds = { + main: main, + categories: categories, + releases: releases + }; +} + +function paginate(set, title) { + var pp = config.postsPerPage || 5 + var pages = []; + for (var i = 0; i < set.length; i += pp) { + pages.push(set.slice(i, i + pp)); + } + var id = title.replace(/[^a-zA-Z0-9.]+/g, '-'); + return { id: id || 'index', pageid: id, posts: set, pages: pages, title: title }; +} + +function writePermalinks(data) { + Object.keys(data.posts).forEach(function(k) { + var post = data.posts[k]; + writeFile(post.permalink, post); + }); +} + +function writeFeeds(data) { + writeFeed(data.feeds.main); + + for (var feed in data.feeds.categories) { + writeFeed(data.feeds.categories[feed]); + } + for (var feed in data.feeds.releases) { + writeFeed(data.feeds.releases[feed]); + } +} + +function writeFeed(feed) { + var title = feed.title; + feed.pages.forEach(function(page, p, pages) { + writePaginated(feed.title, page, p, pages.length, feed.id); + }); +} + +function writePaginated(title, posts, p, total, id) { + var uri = '/' + encodeURIComponent(title) + '/'; + var d = { + title: title, + page: p, + posts: posts, + total: total, + paginated: true, + pageid: id + '-' + p, + uri: uri + }; + if (p === 0) { + writeFile(uri, d); + writeFile('/feed' + uri, d, rssTemplate); + } + writeFile(uri + p, d); + writeFile('/feed' + uri + p, d, rssTemplate); +} + +function buildOutput(data) { + buildPermalinks(data); + buildFeeds(data); + writePermalinks(data); + writeFeeds(data); +} + diff --git a/tools/blog/node_modules/.bin/marked b/tools/blog/node_modules/.bin/marked new file mode 120000 index 00000000000..3b8ef881cb9 --- /dev/null +++ b/tools/blog/node_modules/.bin/marked @@ -0,0 +1 @@ +/Users/isaacs/dev/js/node-master/tools/blog/node_modules/marked/bin/marked \ No newline at end of file diff --git a/tools/gyp/test/mac/app-bundle/empty.c b/tools/blog/node_modules/ejs/.gitmodules similarity index 100% rename from tools/gyp/test/mac/app-bundle/empty.c rename to tools/blog/node_modules/ejs/.gitmodules diff --git a/tools/blog/node_modules/ejs/.npmignore b/tools/blog/node_modules/ejs/.npmignore new file mode 100644 index 00000000000..020ddac2ced --- /dev/null +++ b/tools/blog/node_modules/ejs/.npmignore @@ -0,0 +1,4 @@ +# ignore any vim files: +*.sw[a-z] +vim/.netrwhist +node_modules diff --git a/tools/blog/node_modules/ejs/History.md b/tools/blog/node_modules/ejs/History.md new file mode 100644 index 00000000000..75dc16f51f3 --- /dev/null +++ b/tools/blog/node_modules/ejs/History.md @@ -0,0 +1,98 @@ + +0.7.1 / 2012-03-26 +================== + + * Fixed exception when using express in production caused by typo. [slaskis] + +0.7.0 / 2012-03-24 +================== + + * Added newline consumption support (`-%>`) [whoatemydomain] + +0.6.1 / 2011-12-09 +================== + + * Fixed `ejs.renderFile()` + +0.6.0 / 2011-12-09 +================== + + * Changed: you no longer need `{ locals: {} }` + +0.5.0 / 2011-11-20 +================== + + * Added express 3.x support + * Added ejs.renderFile() + * Added 'json' filter + * Fixed tests for 0.5.x + +0.4.3 / 2011-06-20 +================== + + * Fixed stacktraces line number when used multiline js expressions [Octave] + +0.4.2 / 2011-05-11 +================== + + * Added client side support + +0.4.1 / 2011-04-21 +================== + + * Fixed error context + +0.4.0 / 2011-04-21 +================== + + * Added; ported jade's error reporting to ejs. [slaskis] + +0.3.1 / 2011-02-23 +================== + + * Fixed optional `compile()` options + +0.3.0 / 2011-02-14 +================== + + * Added 'json' filter [Yuriy Bogdanov] + * Use exported version of parse function to allow monkey-patching [Anatoliy Chakkaev] + +0.2.1 / 2010-10-07 +================== + + * Added filter support + * Fixed _cache_ option. ~4x performance increase + +0.2.0 / 2010-08-05 +================== + + * Added support for global tag config + * Added custom tag support. Closes #5 + * Fixed whitespace bug. Closes #4 + +0.1.0 / 2010-08-04 +================== + + * Faster implementation [ashleydev] + +0.0.4 / 2010-08-02 +================== + + * Fixed single quotes for content outside of template tags. [aniero] + * Changed; `exports.compile()` now expects only "locals" + +0.0.3 / 2010-07-15 +================== + + * Fixed single quotes + +0.0.2 / 2010-07-09 +================== + + * Fixed newline preservation + +0.0.1 / 2010-07-09 +================== + + * Initial release diff --git a/tools/blog/node_modules/ejs/Makefile b/tools/blog/node_modules/ejs/Makefile new file mode 100644 index 00000000000..14b93049dae --- /dev/null +++ b/tools/blog/node_modules/ejs/Makefile @@ -0,0 +1,23 @@ + +SRC = $(shell find lib -name "*.js" -type f) +UGLIFY_FLAGS = --no-mangle + +all: ejs.min.js + +test: + @./node_modules/.bin/mocha \ + --ui exports + +ejs.js: $(SRC) + @node support/compile.js $^ + +ejs.min.js: ejs.js + @uglifyjs $(UGLIFY_FLAGS) $< > $@ \ + && du ejs.min.js \ + && du ejs.js + +clean: + rm -f ejs.js + rm -f ejs.min.js + +.PHONY: test \ No newline at end of file diff --git a/tools/blog/node_modules/ejs/Readme.md b/tools/blog/node_modules/ejs/Readme.md new file mode 100644 index 00000000000..8e398fd20c3 --- /dev/null +++ b/tools/blog/node_modules/ejs/Readme.md @@ -0,0 +1,151 @@ + +# EJS + +Embedded JavaScript templates. + +## Installation + + $ npm install ejs + +## Features + + * Complies with the [Express](http://expressjs.com) view system + * Static caching of intermediate JavaScript + * Unbuffered code for conditionals etc `<% code %>` + * Escapes html by default with `<%= code %>` + * Unescaped buffering with `<%- code %>` + * Supports tag customization + * Filter support for designer-friendly templates + * Client-side support + * Newline slurping with `<% code -%>` or `<% -%>` or `<%= code -%>` or `<%- code -%>` + +## Example + + <% if (user) { %> +

    <%= user.name %>

    + <% } %> + +## Usage + + ejs.compile(str, options); + // => Function + + ejs.render(str, options); + // => str + +## Options + + - `cache` Compiled functions are cached, requires `filename` + - `filename` Used by `cache` to key caches + - `scope` Function execution context + - `debug` Output generated function body + - `open` Open tag, defaulting to "<%" + - `close` Closing tag, defaulting to "%>" + - * All others are template-local variables + +## Custom tags + +Custom tags can also be applied globally: + + var ejs = require('ejs'); + ejs.open = '{{'; + ejs.close = '}}'; + +Which would make the following a valid template: + +

    {{= title }}

    + +## Filters + +EJS conditionally supports the concept of "filters". A "filter chain" +is a designer friendly api for manipulating data, without writing JavaScript. + +Filters can be applied by supplying the _:_ modifier, so for example if we wish to take the array `[{ name: 'tj' }, { name: 'mape' }, { name: 'guillermo' }]` and output a list of names we can do this simply with filters: + +Template: + +

    <%=: users | map:'name' | join %>

    + +Output: + +

    Tj, Mape, Guillermo

    + +Render call: + + ejs.render(str, { + users: [ + { name: 'tj' }, + { name: 'mape' }, + { name: 'guillermo' } + ] + }); + +Or perhaps capitalize the first user's name for display: + +

    <%=: users | first | capitalize %>

    + +## Filter list + +Currently these filters are available: + + - first + - last + - capitalize + - downcase + - upcase + - sort + - sort_by:'prop' + - size + - length + - plus:n + - minus:n + - times:n + - divided_by:n + - join:'val' + - truncate:n + - truncate_words:n + - replace:pattern,substitution + - prepend:val + - append:val + - map:'prop' + - reverse + - get:'prop' + +## Adding filters + + To add a filter simply add a method to the `.filters` object: + +```js +ejs.filters.last = function(obj) { + return obj[obj.length - 1]; +}; +``` + +## client-side support + + include `./ejs.js` or `./ejs.min.js` and `require("ejs").compile(str)`. + +## License + +(The MIT License) + +Copyright (c) 2009-2010 TJ Holowaychuk <tj@vision-media.ca> + +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. diff --git a/tools/blog/node_modules/ejs/benchmark.js b/tools/blog/node_modules/ejs/benchmark.js new file mode 100644 index 00000000000..7b267e1603f --- /dev/null +++ b/tools/blog/node_modules/ejs/benchmark.js @@ -0,0 +1,14 @@ + + +var ejs = require('./lib/ejs'), + str = '<% if (foo) { %>

    <%= foo %>

    <% } %>', + times = 50000; + +console.log('rendering ' + times + ' times'); + +var start = new Date; +while (times--) { + ejs.render(str, { cache: true, filename: 'test', locals: { foo: 'bar' }}); +} + +console.log('took ' + (new Date - start) + 'ms'); \ No newline at end of file diff --git a/tools/blog/node_modules/ejs/ejs.js b/tools/blog/node_modules/ejs/ejs.js new file mode 100644 index 00000000000..b0fa93b12bf --- /dev/null +++ b/tools/blog/node_modules/ejs/ejs.js @@ -0,0 +1,567 @@ + +// CommonJS require() + +function require(p){ + if ('fs' == p) return {}; + var path = require.resolve(p) + , mod = require.modules[path]; + if (!mod) throw new Error('failed to require "' + p + '"'); + if (!mod.exports) { + mod.exports = {}; + mod.call(mod.exports, mod, mod.exports, require.relative(path)); + } + return mod.exports; + } + +require.modules = {}; + +require.resolve = function (path){ + var orig = path + , reg = path + '.js' + , index = path + '/index.js'; + return require.modules[reg] && reg + || require.modules[index] && index + || orig; + }; + +require.register = function (path, fn){ + require.modules[path] = fn; + }; + +require.relative = function (parent) { + return function(p){ + if ('.' != p.substr(0, 1)) return require(p); + + var path = parent.split('/') + , segs = p.split('/'); + path.pop(); + + for (var i = 0; i < segs.length; i++) { + var seg = segs[i]; + if ('..' == seg) path.pop(); + else if ('.' != seg) path.push(seg); + } + + return require(path.join('/')); + }; + }; + + +require.register("ejs.js", function(module, exports, require){ + +/*! + * EJS + * Copyright(c) 2010 TJ Holowaychuk + * MIT Licensed + */ + +/** + * Module dependencies. + */ + +var utils = require('./utils') + , fs = require('fs'); + +/** + * Library version. + */ + +exports.version = '0.6.1'; + +/** + * Filters. + * + * @type Object + */ + +var filters = exports.filters = require('./filters'); + +/** + * Intermediate js cache. + * + * @type Object + */ + +var cache = {}; + +/** + * Clear intermediate js cache. + * + * @api public + */ + +exports.clearCache = function(){ + cache = {}; +}; + +/** + * Translate filtered code into function calls. + * + * @param {String} js + * @return {String} + * @api private + */ + +function filtered(js) { + return js.substr(1).split('|').reduce(function(js, filter){ + var parts = filter.split(':') + , name = parts.shift() + , args = parts.shift() || ''; + if (args) args = ', ' + args; + return 'filters.' + name + '(' + js + args + ')'; + }); +}; + +/** + * Re-throw the given `err` in context to the + * `str` of ejs, `filename`, and `lineno`. + * + * @param {Error} err + * @param {String} str + * @param {String} filename + * @param {String} lineno + * @api private + */ + +function rethrow(err, str, filename, lineno){ + var lines = str.split('\n') + , start = Math.max(lineno - 3, 0) + , end = Math.min(lines.length, lineno + 3); + + // Error context + var context = lines.slice(start, end).map(function(line, i){ + var curr = i + start + 1; + return (curr == lineno ? ' >> ' : ' ') + + curr + + '| ' + + line; + }).join('\n'); + + // Alter exception message + err.path = filename; + err.message = (filename || 'ejs') + ':' + + lineno + '\n' + + context + '\n\n' + + err.message; + + throw err; +} + +/** + * Parse the given `str` of ejs, returning the function body. + * + * @param {String} str + * @return {String} + * @api public + */ + +var parse = exports.parse = function(str, options){ + var options = options || {} + , open = options.open || exports.open || '<%' + , close = options.close || exports.close || '%>'; + + var buf = [ + "var buf = [];" + , "\nwith (locals) {" + , "\n buf.push('" + ]; + + var lineno = 1; + + for (var i = 0, len = str.length; i < len; ++i) { + if (str.slice(i, open.length + i) == open) { + i += open.length + + var prefix, postfix, line = '__stack.lineno=' + lineno; + switch (str.substr(i, 1)) { + case '=': + prefix = "', escape((" + line + ', '; + postfix = ")), '"; + ++i; + break; + case '-': + prefix = "', (" + line + ', '; + postfix = "), '"; + ++i; + break; + default: + prefix = "');" + line + ';'; + postfix = "; buf.push('"; + } + + var end = str.indexOf(close, i) + , js = str.substring(i, end) + , start = i + , n = 0; + + while (~(n = js.indexOf("\n", n))) n++, lineno++; + if (js.substr(0, 1) == ':') js = filtered(js); + buf.push(prefix, js, postfix); + i += end - start + close.length - 1; + + } else if (str.substr(i, 1) == "\\") { + buf.push("\\\\"); + } else if (str.substr(i, 1) == "'") { + buf.push("\\'"); + } else if (str.substr(i, 1) == "\r") { + buf.push(" "); + } else if (str.substr(i, 1) == "\n") { + buf.push("\\n"); + lineno++; + } else { + buf.push(str.substr(i, 1)); + } + } + + buf.push("');\n}\nreturn buf.join('');"); + return buf.join(''); +}; + +/** + * Compile the given `str` of ejs into a `Function`. + * + * @param {String} str + * @param {Object} options + * @return {Function} + * @api public + */ + +var compile = exports.compile = function(str, options){ + options = options || {}; + + var input = JSON.stringify(str) + , filename = options.filename + ? JSON.stringify(options.filename) + : 'undefined'; + + // Adds the fancy stack trace meta info + str = [ + 'var __stack = { lineno: 1, input: ' + input + ', filename: ' + filename + ' };', + rethrow.toString(), + 'try {', + exports.parse(str, options), + '} catch (err) {', + ' rethrow(err, __stack.input, __stack.filename, __stack.lineno);', + '}' + ].join("\n"); + + if (options.debug) console.log(str); + var fn = new Function('locals, filters, escape', str); + return function(locals){ + return fn.call(this, locals, filters, utils.escape); + } +}; + +/** + * Render the given `str` of ejs. + * + * Options: + * + * - `locals` Local variables object + * - `cache` Compiled functions are cached, requires `filename` + * - `filename` Used by `cache` to key caches + * - `scope` Function execution context + * - `debug` Output generated function body + * - `open` Open tag, defaulting to "<%" + * - `close` Closing tag, defaulting to "%>" + * + * @param {String} str + * @param {Object} options + * @return {String} + * @api public + */ + +exports.render = function(str, options){ + var fn + , options = options || {}; + + if (options.cache) { + if (options.filename) { + fn = cache[options.filename] || (cache[options.filename] = compile(str, options)); + } else { + throw new Error('"cache" option requires "filename".'); + } + } else { + fn = compile(str, options); + } + + options.__proto__ = options.locals; + return fn.call(options.scope, options); +}; + +/** + * Render an EJS file at the given `path` and callback `fn(err, str)`. + * + * @param {String} path + * @param {Object|Function} options or callback + * @param {Function} fn + * @api public + */ + +exports.renderFile = function(path, options, fn){ + var key = path + ':string'; + + if ('function' == typeof options) { + fn = options, options = {}; + } + + options.filename = path; + + try { + var str = options.cache + ? exports.cache[key] || (exports.cache[key] = fs.readFileSync(path, 'utf8')) + : fs.readFileSync(path, 'utf8'); + + fn(null, exports.render(str, options)); + } catch (err) { + fn(err); + } +}; + +// express support + +exports.__express = exports.renderFile; + +/** + * Expose to require(). + */ + +if (require.extensions) { + require.extensions['.ejs'] = function(module, filename) { + source = require('fs').readFileSync(filename, 'utf-8'); + module._compile(compile(source, {}), filename); + }; +} else if (require.registerExtension) { + require.registerExtension('.ejs', function(src) { + return compile(src, {}); + }); +} + +}); // module: ejs.js + +require.register("filters.js", function(module, exports, require){ + +/*! + * EJS - Filters + * Copyright(c) 2010 TJ Holowaychuk + * MIT Licensed + */ + +/** + * First element of the target `obj`. + */ + +exports.first = function(obj) { + return obj[0]; +}; + +/** + * Last element of the target `obj`. + */ + +exports.last = function(obj) { + return obj[obj.length - 1]; +}; + +/** + * Capitalize the first letter of the target `str`. + */ + +exports.capitalize = function(str){ + str = String(str); + return str[0].toUpperCase() + str.substr(1, str.length); +}; + +/** + * Downcase the target `str`. + */ + +exports.downcase = function(str){ + return String(str).toLowerCase(); +}; + +/** + * Uppercase the target `str`. + */ + +exports.upcase = function(str){ + return String(str).toUpperCase(); +}; + +/** + * Sort the target `obj`. + */ + +exports.sort = function(obj){ + return Object.create(obj).sort(); +}; + +/** + * Sort the target `obj` by the given `prop` ascending. + */ + +exports.sort_by = function(obj, prop){ + return Object.create(obj).sort(function(a, b){ + a = a[prop], b = b[prop]; + if (a > b) return 1; + if (a < b) return -1; + return 0; + }); +}; + +/** + * Size or length of the target `obj`. + */ + +exports.size = exports.length = function(obj) { + return obj.length; +}; + +/** + * Add `a` and `b`. + */ + +exports.plus = function(a, b){ + return Number(a) + Number(b); +}; + +/** + * Subtract `b` from `a`. + */ + +exports.minus = function(a, b){ + return Number(a) - Number(b); +}; + +/** + * Multiply `a` by `b`. + */ + +exports.times = function(a, b){ + return Number(a) * Number(b); +}; + +/** + * Divide `a` by `b`. + */ + +exports.divided_by = function(a, b){ + return Number(a) / Number(b); +}; + +/** + * Join `obj` with the given `str`. + */ + +exports.join = function(obj, str){ + return obj.join(str || ', '); +}; + +/** + * Truncate `str` to `len`. + */ + +exports.truncate = function(str, len){ + str = String(str); + return str.substr(0, len); +}; + +/** + * Truncate `str` to `n` words. + */ + +exports.truncate_words = function(str, n){ + var str = String(str) + , words = str.split(/ +/); + return words.slice(0, n).join(' '); +}; + +/** + * Replace `pattern` with `substitution` in `str`. + */ + +exports.replace = function(str, pattern, substitution){ + return String(str).replace(pattern, substitution || ''); +}; + +/** + * Prepend `val` to `obj`. + */ + +exports.prepend = function(obj, val){ + return Array.isArray(obj) + ? [val].concat(obj) + : val + obj; +}; + +/** + * Append `val` to `obj`. + */ + +exports.append = function(obj, val){ + return Array.isArray(obj) + ? obj.concat(val) + : obj + val; +}; + +/** + * Map the given `prop`. + */ + +exports.map = function(arr, prop){ + return arr.map(function(obj){ + return obj[prop]; + }); +}; + +/** + * Reverse the given `obj`. + */ + +exports.reverse = function(obj){ + return Array.isArray(obj) + ? obj.reverse() + : String(obj).split('').reverse().join(''); +}; + +/** + * Get `prop` of the given `obj`. + */ + +exports.get = function(obj, prop){ + return obj[prop]; +}; + +/** + * Packs the given `obj` into json string + */ +exports.json = function(obj){ + return JSON.stringify(obj); +}; +}); // module: filters.js + +require.register("utils.js", function(module, exports, require){ + +/*! + * EJS + * Copyright(c) 2010 TJ Holowaychuk + * MIT Licensed + */ + +/** + * Escape the given string of `html`. + * + * @param {String} html + * @return {String} + * @api private + */ + +exports.escape = function(html){ + return String(html) + .replace(/&(?!\w+;)/g, '&') + .replace(//g, '>') + .replace(/"/g, '"'); +}; + +}); // module: utils.js diff --git a/tools/blog/node_modules/ejs/ejs.min.js b/tools/blog/node_modules/ejs/ejs.min.js new file mode 100644 index 00000000000..b87881320e3 --- /dev/null +++ b/tools/blog/node_modules/ejs/ejs.min.js @@ -0,0 +1,2 @@ +// CommonJS require() +function require(p){if("fs"==p)return{};var path=require.resolve(p),mod=require.modules[path];if(!mod)throw new Error('failed to require "'+p+'"');mod.exports||(mod.exports={},mod.call(mod.exports,mod,mod.exports,require.relative(path)));return mod.exports}require.modules={},require.resolve=function(path){var orig=path,reg=path+".js",index=path+"/index.js";return require.modules[reg]&®||require.modules[index]&&index||orig},require.register=function(path,fn){require.modules[path]=fn},require.relative=function(parent){return function(p){if("."!=p.substr(0,1))return require(p);var path=parent.split("/"),segs=p.split("/");path.pop();for(var i=0;i> ":" ")+curr+"| "+line}).join("\n");err.path=filename,err.message=(filename||"ejs")+":"+lineno+"\n"+context+"\n\n"+err.message;throw err}var parse=exports.parse=function(str,options){var options=options||{},open=options.open||exports.open||"<%",close=options.close||exports.close||"%>",buf=["var buf = [];","\nwith (locals) {","\n buf.push('"],lineno=1;for(var i=0,len=str.length;ib)return 1;if(a/g,">").replace(/"/g,""")}}) \ No newline at end of file diff --git a/tools/blog/node_modules/ejs/examples/client.html b/tools/blog/node_modules/ejs/examples/client.html new file mode 100644 index 00000000000..51ce0b4ced5 --- /dev/null +++ b/tools/blog/node_modules/ejs/examples/client.html @@ -0,0 +1,24 @@ + + + + + + + + + \ No newline at end of file diff --git a/tools/blog/node_modules/ejs/examples/list.ejs b/tools/blog/node_modules/ejs/examples/list.ejs new file mode 100644 index 00000000000..d571330aeea --- /dev/null +++ b/tools/blog/node_modules/ejs/examples/list.ejs @@ -0,0 +1,7 @@ +<% if (names.length) { %> +
      + <% names.forEach(function(name){ %> +
    • <%= name %>
    • + <% }) %> +
    +<% } %> \ No newline at end of file diff --git a/tools/blog/node_modules/ejs/examples/list.js b/tools/blog/node_modules/ejs/examples/list.js new file mode 100644 index 00000000000..ec614ed6240 --- /dev/null +++ b/tools/blog/node_modules/ejs/examples/list.js @@ -0,0 +1,14 @@ + +/** + * Module dependencies. + */ + +var ejs = require('../') + , fs = require('fs') + , str = fs.readFileSync(__dirname + '/list.ejs', 'utf8'); + +var ret = ejs.render(str, { + names: ['foo', 'bar', 'baz'] +}); + +console.log(ret); \ No newline at end of file diff --git a/tools/blog/node_modules/ejs/index.js b/tools/blog/node_modules/ejs/index.js new file mode 100644 index 00000000000..20bf71a3fc1 --- /dev/null +++ b/tools/blog/node_modules/ejs/index.js @@ -0,0 +1,2 @@ + +module.exports = require('./lib/ejs'); \ No newline at end of file diff --git a/tools/blog/node_modules/ejs/lib/ejs.js b/tools/blog/node_modules/ejs/lib/ejs.js new file mode 100644 index 00000000000..e87b98ea556 --- /dev/null +++ b/tools/blog/node_modules/ejs/lib/ejs.js @@ -0,0 +1,298 @@ + +/*! + * EJS + * Copyright(c) 2012 TJ Holowaychuk + * MIT Licensed + */ + +/** + * Module dependencies. + */ + +var utils = require('./utils') + , fs = require('fs'); + +/** + * Library version. + */ + +exports.version = '0.7.1'; + +/** + * Filters. + * + * @type Object + */ + +var filters = exports.filters = require('./filters'); + +/** + * Intermediate js cache. + * + * @type Object + */ + +var cache = {}; + +/** + * Clear intermediate js cache. + * + * @api public + */ + +exports.clearCache = function(){ + cache = {}; +}; + +/** + * Translate filtered code into function calls. + * + * @param {String} js + * @return {String} + * @api private + */ + +function filtered(js) { + return js.substr(1).split('|').reduce(function(js, filter){ + var parts = filter.split(':') + , name = parts.shift() + , args = parts.shift() || ''; + if (args) args = ', ' + args; + return 'filters.' + name + '(' + js + args + ')'; + }); +}; + +/** + * Re-throw the given `err` in context to the + * `str` of ejs, `filename`, and `lineno`. + * + * @param {Error} err + * @param {String} str + * @param {String} filename + * @param {String} lineno + * @api private + */ + +function rethrow(err, str, filename, lineno){ + var lines = str.split('\n') + , start = Math.max(lineno - 3, 0) + , end = Math.min(lines.length, lineno + 3); + + // Error context + var context = lines.slice(start, end).map(function(line, i){ + var curr = i + start + 1; + return (curr == lineno ? ' >> ' : ' ') + + curr + + '| ' + + line; + }).join('\n'); + + // Alter exception message + err.path = filename; + err.message = (filename || 'ejs') + ':' + + lineno + '\n' + + context + '\n\n' + + err.message; + + throw err; +} + +/** + * Parse the given `str` of ejs, returning the function body. + * + * @param {String} str + * @return {String} + * @api public + */ + +var parse = exports.parse = function(str, options){ + var options = options || {} + , open = options.open || exports.open || '<%' + , close = options.close || exports.close || '%>'; + + var buf = [ + "var buf = [];" + , "\nwith (locals) {" + , "\n buf.push('" + ]; + + var lineno = 1; + + var consumeEOL = false; + for (var i = 0, len = str.length; i < len; ++i) { + if (str.slice(i, open.length + i) == open) { + i += open.length + + var prefix, postfix, line = '__stack.lineno=' + lineno; + switch (str.substr(i, 1)) { + case '=': + prefix = "', escape((" + line + ', '; + postfix = ")), '"; + ++i; + break; + case '-': + prefix = "', (" + line + ', '; + postfix = "), '"; + ++i; + break; + default: + prefix = "');" + line + ';'; + postfix = "; buf.push('"; + } + + var end = str.indexOf(close, i) + , js = str.substring(i, end) + , start = i + , n = 0; + + if ('-' == js[js.length-1]){ + js = js.substring(0, js.length - 2); + consumeEOL = true; + } + + while (~(n = js.indexOf("\n", n))) n++, lineno++; + if (js.substr(0, 1) == ':') js = filtered(js); + buf.push(prefix, js, postfix); + i += end - start + close.length - 1; + + } else if (str.substr(i, 1) == "\\") { + buf.push("\\\\"); + } else if (str.substr(i, 1) == "'") { + buf.push("\\'"); + } else if (str.substr(i, 1) == "\r") { + buf.push(" "); + } else if (str.substr(i, 1) == "\n") { + if (consumeEOL) { + consumeEOL = false; + } else { + buf.push("\\n"); + lineno++; + } + } else { + buf.push(str.substr(i, 1)); + } + } + + buf.push("');\n}\nreturn buf.join('');"); + return buf.join(''); +}; + +/** + * Compile the given `str` of ejs into a `Function`. + * + * @param {String} str + * @param {Object} options + * @return {Function} + * @api public + */ + +var compile = exports.compile = function(str, options){ + options = options || {}; + + var input = JSON.stringify(str) + , filename = options.filename + ? JSON.stringify(options.filename) + : 'undefined'; + + // Adds the fancy stack trace meta info + str = [ + 'var __stack = { lineno: 1, input: ' + input + ', filename: ' + filename + ' };', + rethrow.toString(), + 'try {', + exports.parse(str, options), + '} catch (err) {', + ' rethrow(err, __stack.input, __stack.filename, __stack.lineno);', + '}' + ].join("\n"); + + if (options.debug) console.log(str); + var fn = new Function('locals, filters, escape', str); + return function(locals){ + return fn.call(this, locals, filters, utils.escape); + } +}; + +/** + * Render the given `str` of ejs. + * + * Options: + * + * - `locals` Local variables object + * - `cache` Compiled functions are cached, requires `filename` + * - `filename` Used by `cache` to key caches + * - `scope` Function execution context + * - `debug` Output generated function body + * - `open` Open tag, defaulting to "<%" + * - `close` Closing tag, defaulting to "%>" + * + * @param {String} str + * @param {Object} options + * @return {String} + * @api public + */ + +exports.render = function(str, options){ + var fn + , options = options || {}; + + if (options.cache) { + if (options.filename) { + fn = cache[options.filename] || (cache[options.filename] = compile(str, options)); + } else { + throw new Error('"cache" option requires "filename".'); + } + } else { + fn = compile(str, options); + } + + options.__proto__ = options.locals; + return fn.call(options.scope, options); +}; + +/** + * Render an EJS file at the given `path` and callback `fn(err, str)`. + * + * @param {String} path + * @param {Object|Function} options or callback + * @param {Function} fn + * @api public + */ + +exports.renderFile = function(path, options, fn){ + var key = path + ':string'; + + if ('function' == typeof options) { + fn = options, options = {}; + } + + options.filename = path; + + try { + var str = options.cache + ? cache[key] || (cache[key] = fs.readFileSync(path, 'utf8')) + : fs.readFileSync(path, 'utf8'); + + fn(null, exports.render(str, options)); + } catch (err) { + fn(err); + } +}; + +// express support + +exports.__express = exports.renderFile; + +/** + * Expose to require(). + */ + +if (require.extensions) { + require.extensions['.ejs'] = function(module, filename) { + source = require('fs').readFileSync(filename, 'utf-8'); + module._compile(compile(source, {}), filename); + }; +} else if (require.registerExtension) { + require.registerExtension('.ejs', function(src) { + return compile(src, {}); + }); +} diff --git a/tools/blog/node_modules/ejs/lib/filters.js b/tools/blog/node_modules/ejs/lib/filters.js new file mode 100644 index 00000000000..d425c8d89e1 --- /dev/null +++ b/tools/blog/node_modules/ejs/lib/filters.js @@ -0,0 +1,198 @@ + +/*! + * EJS - Filters + * Copyright(c) 2010 TJ Holowaychuk + * MIT Licensed + */ + +/** + * First element of the target `obj`. + */ + +exports.first = function(obj) { + return obj[0]; +}; + +/** + * Last element of the target `obj`. + */ + +exports.last = function(obj) { + return obj[obj.length - 1]; +}; + +/** + * Capitalize the first letter of the target `str`. + */ + +exports.capitalize = function(str){ + str = String(str); + return str[0].toUpperCase() + str.substr(1, str.length); +}; + +/** + * Downcase the target `str`. + */ + +exports.downcase = function(str){ + return String(str).toLowerCase(); +}; + +/** + * Uppercase the target `str`. + */ + +exports.upcase = function(str){ + return String(str).toUpperCase(); +}; + +/** + * Sort the target `obj`. + */ + +exports.sort = function(obj){ + return Object.create(obj).sort(); +}; + +/** + * Sort the target `obj` by the given `prop` ascending. + */ + +exports.sort_by = function(obj, prop){ + return Object.create(obj).sort(function(a, b){ + a = a[prop], b = b[prop]; + if (a > b) return 1; + if (a < b) return -1; + return 0; + }); +}; + +/** + * Size or length of the target `obj`. + */ + +exports.size = exports.length = function(obj) { + return obj.length; +}; + +/** + * Add `a` and `b`. + */ + +exports.plus = function(a, b){ + return Number(a) + Number(b); +}; + +/** + * Subtract `b` from `a`. + */ + +exports.minus = function(a, b){ + return Number(a) - Number(b); +}; + +/** + * Multiply `a` by `b`. + */ + +exports.times = function(a, b){ + return Number(a) * Number(b); +}; + +/** + * Divide `a` by `b`. + */ + +exports.divided_by = function(a, b){ + return Number(a) / Number(b); +}; + +/** + * Join `obj` with the given `str`. + */ + +exports.join = function(obj, str){ + return obj.join(str || ', '); +}; + +/** + * Truncate `str` to `len`. + */ + +exports.truncate = function(str, len){ + str = String(str); + return str.substr(0, len); +}; + +/** + * Truncate `str` to `n` words. + */ + +exports.truncate_words = function(str, n){ + var str = String(str) + , words = str.split(/ +/); + return words.slice(0, n).join(' '); +}; + +/** + * Replace `pattern` with `substitution` in `str`. + */ + +exports.replace = function(str, pattern, substitution){ + return String(str).replace(pattern, substitution || ''); +}; + +/** + * Prepend `val` to `obj`. + */ + +exports.prepend = function(obj, val){ + return Array.isArray(obj) + ? [val].concat(obj) + : val + obj; +}; + +/** + * Append `val` to `obj`. + */ + +exports.append = function(obj, val){ + return Array.isArray(obj) + ? obj.concat(val) + : obj + val; +}; + +/** + * Map the given `prop`. + */ + +exports.map = function(arr, prop){ + return arr.map(function(obj){ + return obj[prop]; + }); +}; + +/** + * Reverse the given `obj`. + */ + +exports.reverse = function(obj){ + return Array.isArray(obj) + ? obj.reverse() + : String(obj).split('').reverse().join(''); +}; + +/** + * Get `prop` of the given `obj`. + */ + +exports.get = function(obj, prop){ + return obj[prop]; +}; + +/** + * Packs the given `obj` into json string + */ +exports.json = function(obj){ + return JSON.stringify(obj); +}; \ No newline at end of file diff --git a/tools/blog/node_modules/ejs/lib/utils.js b/tools/blog/node_modules/ejs/lib/utils.js new file mode 100644 index 00000000000..8d569d6f23f --- /dev/null +++ b/tools/blog/node_modules/ejs/lib/utils.js @@ -0,0 +1,23 @@ + +/*! + * EJS + * Copyright(c) 2010 TJ Holowaychuk + * MIT Licensed + */ + +/** + * Escape the given string of `html`. + * + * @param {String} html + * @return {String} + * @api private + */ + +exports.escape = function(html){ + return String(html) + .replace(/&(?!\w+;)/g, '&') + .replace(//g, '>') + .replace(/"/g, '"'); +}; + \ No newline at end of file diff --git a/tools/blog/node_modules/ejs/package.json b/tools/blog/node_modules/ejs/package.json new file mode 100644 index 00000000000..0458a444652 --- /dev/null +++ b/tools/blog/node_modules/ejs/package.json @@ -0,0 +1,23 @@ +{ + "name": "ejs", + "description": "Embedded JavaScript templates", + "version": "0.7.1", + "author": { + "name": "TJ Holowaychuk", + "email": "tj@vision-media.ca" + }, + "keywords": [ + "template", + "engine", + "ejs" + ], + "devDependencies": { + "mocha": "*" + }, + "main": "./lib/ejs.js", + "_id": "ejs@0.7.1", + "dist": { + "shasum": "9ed557b7e65f9f1adf5473060d079141ad7e680b" + }, + "_from": "ejs" +} diff --git a/tools/blog/node_modules/ejs/support/compile.js b/tools/blog/node_modules/ejs/support/compile.js new file mode 100644 index 00000000000..95cafc88d04 --- /dev/null +++ b/tools/blog/node_modules/ejs/support/compile.js @@ -0,0 +1,174 @@ + +/** + * Module dependencies. + */ + +var fs = require('fs'); + +/** + * Arguments. + */ + +var args = process.argv.slice(2) + , pending = args.length + , files = {}; + +console.log(''); + +// parse arguments + +args.forEach(function(file){ + var mod = file.replace('lib/', ''); + fs.readFile(file, 'utf8', function(err, js){ + if (err) throw err; + console.log(' \033[90mcompile : \033[0m\033[36m%s\033[0m', file); + files[file] = parse(js); + --pending || compile(); + }); +}); + +/** + * Parse the given `js`. + */ + +function parse(js) { + return parseInheritance(parseConditionals(js)); +} + +/** + * Parse __proto__. + */ + +function parseInheritance(js) { + return js + .replace(/^ *(\w+)\.prototype\.__proto__ * = *(\w+)\.prototype *;?/gm, function(_, child, parent){ + return child + '.prototype = new ' + parent + ';\n' + + child + '.prototype.constructor = '+ child + ';\n'; + }); +} + +/** + * Parse the given `js`, currently supporting: + * + * 'if' ['node' | 'browser'] + * 'end' + * + */ + +function parseConditionals(js) { + var lines = js.split('\n') + , len = lines.length + , buffer = true + , browser = false + , buf = [] + , line + , cond; + + for (var i = 0; i < len; ++i) { + line = lines[i]; + if (/^ *\/\/ *if *(node|browser)/gm.exec(line)) { + cond = RegExp.$1; + buffer = browser = 'browser' == cond; + } else if (/^ *\/\/ *end/.test(line)) { + buffer = true; + browser = false; + } else if (browser) { + buf.push(line.replace(/^( *)\/\//, '$1')); + } else if (buffer) { + buf.push(line); + } + } + + return buf.join('\n'); +} + +/** + * Compile the files. + */ + +function compile() { + var buf = ''; + buf += '\n// CommonJS require()\n\n'; + buf += browser.require + '\n\n'; + buf += 'require.modules = {};\n\n'; + buf += 'require.resolve = ' + browser.resolve + ';\n\n'; + buf += 'require.register = ' + browser.register + ';\n\n'; + buf += 'require.relative = ' + browser.relative + ';\n\n'; + args.forEach(function(file){ + var js = files[file]; + file = file.replace('lib/', ''); + buf += '\nrequire.register("' + file + '", function(module, exports, require){\n'; + buf += js; + buf += '\n}); // module: ' + file + '\n'; + }); + fs.writeFile('ejs.js', buf, function(err){ + if (err) throw err; + console.log(' \033[90m create : \033[0m\033[36m%s\033[0m', 'ejs.js'); + console.log(); + }); +} + +// refactored version of weepy's +// https://github.com/weepy/brequire/blob/master/browser/brequire.js + +var browser = { + + /** + * Require a module. + */ + + require: function require(p){ + if ('fs' == p) return {}; + var path = require.resolve(p) + , mod = require.modules[path]; + if (!mod) throw new Error('failed to require "' + p + '"'); + if (!mod.exports) { + mod.exports = {}; + mod.call(mod.exports, mod, mod.exports, require.relative(path)); + } + return mod.exports; + }, + + /** + * Resolve module path. + */ + + resolve: function(path){ + var orig = path + , reg = path + '.js' + , index = path + '/index.js'; + return require.modules[reg] && reg + || require.modules[index] && index + || orig; + }, + + /** + * Return relative require(). + */ + + relative: function(parent) { + return function(p){ + if ('.' != p.substr(0, 1)) return require(p); + + var path = parent.split('/') + , segs = p.split('/'); + path.pop(); + + for (var i = 0; i < segs.length; i++) { + var seg = segs[i]; + if ('..' == seg) path.pop(); + else if ('.' != seg) path.push(seg); + } + + return require(path.join('/')); + }; + }, + + /** + * Register a module. + */ + + register: function(path, fn){ + require.modules[path] = fn; + } +}; \ No newline at end of file diff --git a/tools/blog/node_modules/ejs/test/ejs.test.js b/tools/blog/node_modules/ejs/test/ejs.test.js new file mode 100644 index 00000000000..54b8d2dacc0 --- /dev/null +++ b/tools/blog/node_modules/ejs/test/ejs.test.js @@ -0,0 +1,329 @@ + +/** + * Module dependencies. + */ + +var ejs = require('../') + , assert = require('assert'); + +module.exports = { + 'test .version': function(){ + assert.ok(/^\d+\.\d+\.\d+$/.test(ejs.version), 'Test .version format'); + }, + + 'test html': function(){ + assert.equal('

    yay

    ', ejs.render('

    yay

    ')); + }, + + 'test renderFile': function(){ + var html = '

    tj

    ', + str = '

    <%= name %>

    ', + options = { name: 'tj', open: '{', close: '}' }; + + ejs.renderFile(__dirname + '/fixtures/user.ejs', options, function(err, res){ + assert.ok(!err); + assert.equal(res, html); + }) + }, + + 'test buffered code': function(){ + var html = '

    tj

    ', + str = '

    <%= name %>

    ', + locals = { name: 'tj' }; + assert.equal(html, ejs.render(str, { locals: locals })); + }, + + 'test unbuffered code': function(){ + var html = '

    tj

    ', + str = '<% if (name) { %>

    <%= name %>

    <% } %>', + locals = { name: 'tj' }; + assert.equal(html, ejs.render(str, { locals: locals })); + }, + + 'test `scope` option': function(){ + var html = '

    tj

    ', + str = '

    <%= this %>

    '; + assert.equal(html, ejs.render(str, { scope: 'tj' })); + }, + + 'test escaping': function(){ + assert.equal('<script>', ejs.render('<%= "