Closed leiminghany closed 5 years ago
Hey,
What's the "home of JavaScript" if not for the directory where node_modules
are in? Are you saying require("some-module")
in ./app/assets/javascripts
isn't resolved to node_modules
that's a few directories up?
you can see gitlab project source https://gitlab.com/gitlab-org/gitlab.
all the javascript are placed in ./app/assets/javascripts
. but the package.json and node_modules are still paced in './'
Are you saying require("some-module") in ./app/assets/javascripts isn't resolved to node_modules
when require("some-module"), it resolved to node_modules. BUT, if require a absolute path like ~/lib/tools.js
, it SHOULD resolve to app/assets/javascripts/lib/tools.js
, But it doesn't, the app/assets/javascripts/
is not added.
Now I simply replaced the sentence https://github.com/moll/vim-node/blob/ede047791792b9530ba1ae73ed86e9671cdd96b8/autoload/node.vim#L33 to let &l:includeexpr = "substitute(v:fname,'\\~','app\\/assets\\/javascripts\\/','g')"
for working around it
when require("some-module"), it resolved to node_modules. BUT, if require a absolute path like ~/lib/tools.js, it SHOULD resolve to app/assets/javascripts/lib/tools.js, But it doesn't, the app/assets/javascripts/ is not added.
To be correct, ~/lib/tools.js
isn't an absolute path. It's just a relative path to a module named ~
. ~
is only magic inside shells, elsewhere it's just a filename. But I know the pattern in general — I use "root" as the magic module to have project-relative includes. What I propose and what you could propose in turn to GitLab is for them to add a symlink to node_modules
for ~
and commit that to the repo. The symlink should resolve to ../app/assets/javascripts
. That solution would be compatible with all existing Node.js tooling, incl. Node.js itself. For a concrete example, here's what it looks if the symlink is named root
: https://github.com/rahvaalgatus/rahvaalgatus/tree/master/node_modules
Here's how it would be made:
ln -s ../app/assets/javascripts node_modules/~
Let me know if that works.
when require("some-module"), it resolved to node_modules. BUT, if require a absolute path like ~/lib/tools.js, it SHOULD resolve to app/assets/javascripts/lib/tools.js, But it doesn't, the app/assets/javascripts/ is not added.
To be correct,
~/lib/tools.js
isn't an absolute path. It's just a relative path to a module named~
.~
is only magic inside shells, elsewhere it's just a filename. But I know the pattern in general — I use "root" as the magic module to have project-relative includes. What I propose and what you could propose in turn to GitLab is for them to add a symlink tonode_modules
for~
and commit that to the repo. The symlink should resolve to../app/assets/javascripts
. That solution would be compatible with all existing Node.js tooling, incl. Node.js itself. For a concrete example, here's what it looks if the symlink is namedroot
: https://github.com/rahvaalgatus/rahvaalgatus/tree/master/node_modulesHere's how it would be made:
ln -s ../app/assets/javascripts node_modules/~
Let me know if that works.
it can work after added the symlink. Thank you very much! @moll
Glad to hear that.
gitlab has a file structure:
The home of javascript is not exactly the PROJECT_HOME(the directory which package.json/node_modules are in). but the
${PROJECT_HOME}/app/assets/javascripts
In this situation, the
gf
command can't work due to the node#lib#find can't support this file structure.