Skip to content

Commit

Permalink
Improve discovery of coroutine shim
Browse files Browse the repository at this point in the history
The fiber-shim script couldn't find coroutine.so on npm installations
with unexcepted configurations. This makes the script use
require.resolve() internally which should improve compatibility.

Closes gh-9
  • Loading branch information
laverdet committed Feb 24, 2011
1 parent 9a14781 commit 35821e1
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 30 deletions.
24 changes: 0 additions & 24 deletions bin/fiber-shim

This file was deleted.

33 changes: 32 additions & 1 deletion bin/node-fibers
Original file line number Diff line number Diff line change
@@ -1,2 +1,33 @@
#!/bin/bash
`dirname "$0"`/fiber-shim node "$@"

NODE=`which node`
if [[ -z "$NODE" ]]; then
echo "Could not find node in PATH!" 1>&2
exit 1
fi

if [[ -e `dirname "$0"`/../src/fibers.node ]]; then
# running straight from dist
FIBERS_ROOT=`dirname "$0"`/../src
else
# in npm
FIBERS_PATH=`echo 'require.resolve("fibers")' | $NODE | head -n1 | egrep -o '/[^'\'']+'`
FIBERS_ROOT=`dirname "$FIBERS_PATH"`/src
if [[ ! -e "$FIBERS_ROOT/fibers.node" ]]; then
echo "Could not find the coroutine shim!" 1>&2
exit 1
fi
fi

UNAME=`uname`
if [[ "$UNAME" == "Linux" ]]; then
FIBER_SHIM=1 \
LD_PRELOAD="$FIBERS_ROOT/coroutine.so" \
$NODE "$@"
elif [[ "$UNAME" == "Darwin" ]]; then
FIBER_SHIM=1 \
DYLD_INSERT_LIBRARIES="$FIBERS_ROOT/coroutine.dylib" \
DYLD_FORCE_FLAT_NAMESPACE=1 \
DYLD_LIBRARY_PATH="$FIBERS_ROOT" \
$NODE "$@"
fi
2 changes: 1 addition & 1 deletion fibers.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var fs = require('fs');

if (fs.statSync(process.execPath).mtime >
fs.statSync(__dirname + '/src/fibers.node').mtime) {
fs.statSync(require.resolve('./src/fibers')).mtime) {
throw new Error(
'`node` has a newer mtime than `fiber`; it is possible your build is out of date. This ' +
'could happen if you upgrade node. Try `npm rebuild fibers` to rebuild. If that doesn\'t ' +
Expand Down
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fibers",
"version": "0.2.1",
"version": "0.2.2",
"description": "Cooperative multi-tasking for Javascript; or, the closest thing to a thread you'll see in node",
"keywords": ["fiber", "fibers", "coroutine", "thread", "async", "parallel", "worker"],
"homepage": "https://github.com/laverdet/node-fibers",
Expand All @@ -10,8 +10,7 @@
"install": "make clean all"
},
"bin": {
"node-fibers": "./bin/node-fibers",
"fiber-shim": "./bin/fiber-shim"
"node-fibers": "./bin/node-fibers"
},
"man": "./man/fibers.1",
"repository": {
Expand All @@ -20,6 +19,6 @@
},
"os": ["macos", "linux"],
"engines": {
"node": ">=0.2.0"
"node": ">=0.3.0"
}
}

0 comments on commit 35821e1

Please sign in to comment.