How to execute `npm install` in a subdirectory?

648 views
Skip to first unread message

Chiel Kunkels

unread,
Mar 9, 2015, 12:51:48 PM3/9/15
to capis...@googlegroups.com

I'm trying to execute npm install in a subdirectory before the release is symlinked, because composer installs a package which requires it.

However, when I try

within release_path + '/foo/bar' do
  execute :npm, 'install'

It can't install, cause it only sees /foo/bar as the path... am I missing something?

Lee Hambley

unread,
Mar 9, 2015, 12:57:17 PM3/9/15
to Capistrano
I'd suggest debugging that this isn't some weird issue with NPM by doing the following:
within release_path + '/foo/bar' do
  puts capture(:pwd)
​Beyond that beware perhaps that `release_path` isn't safe for use at some points in the release workflow, but I can't tell you off the top of my head exactly where.​ It should be safe to use after/in `deploy:updating`. See http://capistranorb.com/documentation/getting-started/flow/


--
You received this message because you are subscribed to the Google Groups "Capistrano" group.
To unsubscribe from this group and stop receiving emails from it, send an email to capistrano+...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/capistrano/b9dfc621-108f-4492-91b5-8202c92e432a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Lee Hambley

unread,
Mar 9, 2015, 12:58:16 PM3/9/15
to Capistrano
I forgot to mention that you can find plenty of other similar issues with workarounds on Stackoverflow, although many of the workarounds look valid, most of them have misappropriated the blame to something that doesn't apply here (whitespace in the command, then blocks like `within()` have no effect).

Chiel Kunkels

unread,
Mar 9, 2015, 1:11:52 PM3/9/15
to capis...@googlegroups.com
I've tried amending my code to the following:

  task :npm_install do
    on roles(:app) do
      within release_path + '/vendor/strangelove/cms' do
        puts capture(:pwd)
      end
    end
  end

but that fails with the following message:

DEBUG [b97cf958] Running /usr/bin/env if test ! -d /vendor/strangelove/cms; then echo "Directory does not exist '/vendor/strangelove/cms'" 1>&2; false; fi as deploy@<ip>
DEBUG [b97cf958] Command: if test ! -d /vendor/strangelove/cms; then echo "Directory does not exist '/vendor/strangelove/cms'" 1>&2; false; fi
DEBUG [b97cf958]        Directory does not exist '/vendor/strangelove/cms'
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as deploy@<ip>: if test ! -d /vendor/strangelove/cms; then echo "Directory does not exist '/vendor/strangelove/cms'" 1>&2; false; fi exit status: 1
if test ! -d /vendor/strangelove/cms; then echo "Directory does not exist '/vendor/strangelove/cms'" 1>&2; false; fi stdout: Nothing written
if test ! -d /vendor/strangelove/cms; then echo "Directory does not exist '/vendor/strangelove/cms'" 1>&2; false; fi stderr: Directory does not exist '/vendor/strangelove/cms'

SSHKit::Command::Failed: if test ! -d /vendor/strangelove/cms; then echo "Directory does not exist '/vendor/strangelove/cms'" 1>&2; false; fi exit status: 1
if test ! -d /vendor/strangelove/cms; then echo "Directory does not exist '/vendor/strangelove/cms'" 1>&2; false; fi stdout: Nothing written
if test ! -d /vendor/strangelove/cms; then echo "Directory does not exist '/vendor/strangelove/cms'" 1>&2; false; fi stderr: Directory does not exist '/vendor/strangelove/cms'

Tasks: TOP => odyssey:npm_install
(See full trace by running task with --trace)
The deploy has failed with an error: Exception while executing as deploy@<ip>: if test ! -d /vendor/strangelove/cms; then echo "Directory does not exist '/vendor/strangelove/cms'" 1>&2; false; fi exit status: 1
if test ! -d /vendor/strangelove/cms; then echo "Directory does not exist '/vendor/strangelove/cms'" 1>&2; false; fi stdout: Nothing written
if test ! -d /vendor/strangelove/cms; then echo "Directory does not exist '/vendor/strangelove/cms'" 1>&2; false; fi stderr: Directory does not exist '/vendor/strangelove/cms'

Which, in a way, is entirely accurate since that directory does not exist. For some reason the release_path is not being prepended.

If I change the code to

  task :npm_install do
    on roles(:app) do
      puts release_path
      puts release_path + '/vendor/strangelove/cms'
      within release_path.join('/vendor/strangelove/cms') do
        puts capture(:pwd)
      end
    end
  end

It does output the release path properly with the first puts statement, but the second one only has the `vendor/strangelove/cms` bit.

Rob Biedenharn

unread,
Mar 9, 2015, 1:29:42 PM3/9/15
to capis...@googlegroups.com
Assuming release_path is a Pathname object, you want to have:

release_path.join('vendor/strangelove/cms')

if vendor is a subdirectory of release_path

If you use '/vendor' (note the initial '/'), you'll get back an absolute path:

-Rob

--
You received this message because you are subscribed to the Google Groups "Capistrano" group.
To unsubscribe from this group and stop receiving emails from it, send an email to capistrano+...@googlegroups.com.

Chiel Kunkels

unread,
Mar 9, 2015, 4:12:03 PM3/9/15
to capis...@googlegroups.com
That worked! Thanks a bunch, I had tried .join('/vendor/strangelove/cms'), but as you pointed out, that returned an absolute path.

Cheers,
Chiel
Reply all
Reply to author
Forward
0 new messages