Skip to content
This repository has been archived by the owner on Jan 15, 2024. It is now read-only.

create version-aware executables to provide multiple npm installations #112

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ before_install:
script: "rake test"

gemfile: .gemfile

sudo: false
11 changes: 11 additions & 0 deletions lib/puppet/parser/functions/npm_version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Puppet::Parser::Functions
newfunction(:npm_version, :type => :rvalue) do |args|
node_unpack_folder = args.shift
version = `#{node_unpack_folder}/bin/npm -v`
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be wrapped into a function as executing this command causes issues with the tests


# the version will be extracted from the CLI.
# the output contains a line break, but this line break causes weird
# symlink names, so the version needs to be stripped.
version.strip
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the v- prefix is missing

end
end
13 changes: 13 additions & 0 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@
$node_symlink_target = "${node_unpack_folder}/bin/node"
$node_symlink = "${node_target_dir}/node-${node_version}"

$npm_version = npm_version($node_unpack_folder)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

calling a function before running the resources may cause a dependency conflict

$npm_target_dir = "${node_unpack_folder}/bin"
$npm_filename = "${node_target_dir}/npm-${npm_version}"

ensure_resource('file', 'nodejs-install-dir', {
ensure => 'directory',
path => $::nodejs::params::install_dir,
Expand Down Expand Up @@ -207,4 +211,13 @@
],
}
}
else {
$npm_template_name = "${module_name}/npm.erb"

file { $npm_filename:
ensure => file,
mode => '0777',
content => template($npm_template_name)
}
}
}
2 changes: 2 additions & 0 deletions templates/npm.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env bash
<%= @node_symlink %> <%= @node_unpack_folder %>/bin/npm $@