kolodny / wavy

use ~ in require and import calls
378 stars 20 forks source link

another npm installer compatibility #4

Closed 59naga closed 8 years ago

59naga commented 8 years ago

wow, wavy is a cool solution to the relative path problem!

mkdir foo && cd foo
echo 'module.exports="foo"' > index.js

npm install wavy
node -e "console.log(require('~/index.js'))"
# foo

but, directory location of pnpm and ied is different from the npm. therefore, the following will fail.

mkdir foo && cd foo
echo 'module.exports="foo"' > index.js

pnpm install wavy
#  wavy                                                              ERROR ✗
#  wavy@1.0.1! $ node postinstall
#  wavy@1.0.1! fs.js:945
#  wavy@1.0.1!   return binding.symlink(preprocessSymlinkDestination(target, type, path),
#  wavy@1.0.1!                  ^
#  wavy@1.0.1! Error: ENOENT: no such file or directory, symlink '/Users/59naga/Downloads/hoge/node_modules/.tmp' -> '/Users/59naga/Downloads/hoge/node_modules/.tmp/node_modules/~'
#  wavy@1.0.1!     at Error (native)
#  wavy@1.0.1!     at Object.fs.symlinkSync (fs.js:945:18)
#  wavy@1.0.1!     at Object.<anonymous> (/Users/59naga/Downloads/hoge/node_modules/.tmp/af2b9dbf-05ed-448c-a208-03cca5c4b39e/_/postinstall.js:7:6)
#  wavy@1.0.1!     at Module._compile (module.js:413:34)
#  wavy@1.0.1!     at Object.Module._extensions..js (module.js:422:10)
#  wavy@1.0.1!     at Module.load (module.js:357:32)
#  wavy@1.0.1!     at Function.Module._load (module.js:314:12)
#  wavy@1.0.1!     at Function.Module.runMain (module.js:447:10)
#  wavy@1.0.1!     at startup (node.js:146:18)
#  wavy@1.0.1!     at node.js:404:3
#
# ! Exit code 1
node -e "console.log(require('~/index.js'))"
# Error: Cannot find module '~/index.js'
mkdir foo && cd foo
echo 'module.exports="foo"' > index.js

ied install wavy
node -e "console.log(require('~/index.js'))"
# Error: Cannot find module '~/index.js'

in a project that huge dependency exists, these installer will come in handy. usually, npm install takes several tens of minutes, but they can be completed in a few tens of seconds!

kolodny commented 8 years ago

Interesting, I never thought about other package managers. It appears to be working for me in ied. Is it possible you don't have a package.json file in the root of the project?

cd $(mktemp -d -t tmp)
echo '{}' > package.json
echo 'module.exports="foo"' > index.js
ied install wavy
node -e "console.log(require('~/index.js'))"
# outputs "foo"

Fixing pnpm requires more of a hack. I need to change this line into something like:

var root = __dirname.slice(0, __dirname.lastIndexOf('/node_modules/'));

I want to do some more testing and clean up the docs before pushing the next release tho. If it's blocking you, feel free to fork with those changes

59naga commented 8 years ago

sounds good, the fix appears to work. FYR: i also tried to write a test in ied and pnpm, but both are not compatible with the local installation(eg pnpm install ../../).

so, additional testing is required is unlikely (should perform only the operation guarantee in npm).

59naga commented 8 years ago

https://github.com/kolodny/wavy/commit/a3bce9882450e532171aa5c921991dc72136d261 do work on pnpm. ready to ship it?

kolodny commented 8 years ago

published in 1.0.2