Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to install npm deps from package.json #300

Merged
merged 1 commit into from Oct 5, 2017
Merged

Add an option to install npm deps from package.json #300

merged 1 commit into from Oct 5, 2017

Conversation

poikilotherm
Copy link
Contributor

Dear maintainers of voxpopuli,

I found #154 and #167 and needed the functionality for myself (installing a Mathoid server, which is based on NodeJS).

Thus I added the necessary bits and would be glad if this would be merged upstream. From my point of view, the code should be idempotent.

Thanks in advance!

Cheers,
Oliver

manifests/npm.pp Outdated
) {

validate_re($ensure, '^[^<>=]', "The ${module_name}::npm defined type does not accept version ranges")
validate_array($install_options)
validate_string($package)
validate_absolute_path($target)
validate_array($uninstall_options)
validate_bool($use_package_json)
Copy link
Contributor

Choose a reason for hiding this comment

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

If you rebase, this should now use data types instead (remove validate_bool, and update
$use_package_json = false,
to
Boolean $use_package_json = false,
e.g., https://github.com/voxpupuli/puppet-nodejs/blob/master/manifests/init.pp#L4

Copy link
Member

Choose a reason for hiding this comment

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

True, but probably better to change all of these in a new PR, now this one

}

$list_command = "${npm_path} ls --long --parseable"
$install_check = "${list_command} | ${grep_command} \"${target}${dirsep}node_modules${dirsep}${install_check_package_string}\""
Copy link
Member

Choose a reason for hiding this comment

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

I have mixed feelings about a using a variable for a directory separator in a string - I personally prefer explicit versus implicit values for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IMHO this makes the code more readable - the string just differ by the dir seps...

Maybe let's replace it with a call to regsubst on Windows to replace / with \\?

Copy link
Member

Choose a reason for hiding this comment

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

Maybe let's replace it with a call to regsubst on Windows to replace / with \?

That's an idea. Not sure if there will be unintended side-effects to doing this though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe this is not even necessary...

According to https://docs.puppet.com/puppet/5.2/lang_windows_file_paths.html#when-to-use-each-kind-of-slash, we can just use slashes.

I don't have a Windows Puppet at hands to prove this true or false - anything available on your side?

Copy link
Member

Choose a reason for hiding this comment

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

@poikilotherm Er I'm not sure if I'm much help - I haven't tested Puppet on Windows with anything for...quite some some time. Looking at the docs in more detail though, it seems as though we do care about what type of slashes, because we're using cmd.exe to run the grep-alternative and cmd.exe requires backslashes.

Copy link
Contributor

Choose a reason for hiding this comment

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

/ should just work, both in puppet and in node.

manifests/npm.pp Outdated
) {

validate_re($ensure, '^[^<>=]', "The ${module_name}::npm defined type does not accept version ranges")
validate_array($install_options)
validate_string($package)
validate_absolute_path($target)
validate_array($uninstall_options)
validate_bool($use_package_json)
Copy link
Member

Choose a reason for hiding this comment

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

True, but probably better to change all of these in a new PR, now this one

@poikilotherm
Copy link
Contributor Author

Hi @ALL,

I just rebased... Do you prefer a single commit for all changes? (I personally prefer to seperate code, tests and doc changes in different commits.)

Cheers,
Oliver

@juniorsysadmin
Copy link
Member

Do you prefer a single commit for all changes

I do. But CONTRIBUTING.md just says "squash your commits down into logical components"

@juniorsysadmin juniorsysadmin added enhancement New feature or request and removed needs-rebase needs-squash labels Sep 26, 2017
…s::npm

* Extended defined type.
* Added spec testing for new option to use package.json.
* Updated docs in README.md about package.json usage.
@poikilotherm
Copy link
Contributor Author

poikilotherm commented Sep 26, 2017

Squashed as requested. Please merge :-)

Sorry, overlooked your comment about regsubst...

@wyardley
Copy link
Contributor

wyardley commented Oct 3, 2017

@poikilotherm @juniorsysadmin I think a single commit is fine. The logical components bit is mostly just saying that it's Ok to break up the commits if they're done in a logical way.
What vox mostly tries to avoid is

  • Update type to foo
  • Fixed typo
  • ASDF
  • I don't know what this is for
  • Updated spec tests

So, squashing to a single commit is usually appropriate for smaller changes. If it's a really big changeset, I have found that breaking it up into chunks can make it easier for the reviewer. However, it can make rebasing a pain sometimes too.

@juniorsysadmin
Copy link
Member

@poikilotherm Merge, or don't merge just yet?

@poikilotherm
Copy link
Contributor Author

I'm ok with the / and \ thing as it is right now. If your can live with it, please go ahead and merge... :-)

@@ -10,6 +10,7 @@
Array $uninstall_options = [],
$home_dir = '/root',
$user = undef,
Boolean $use_package_json = false,
Copy link
Member

Choose a reason for hiding this comment

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

datatypes \o/

Uninstall dependencies from package.json:

```puppet
nodejs::npm { 'serverapp':
Copy link
Member

Choose a reason for hiding this comment

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

docs \o/

@bastelfreak
Copy link
Member

Thanks for the PR @poikilotherm!

@bastelfreak bastelfreak merged commit 2944c09 into voxpupuli:master Oct 5, 2017
@bastelfreak bastelfreak changed the title Adding an option to install npm deps from package.json Add an option to install npm deps from package.json Oct 5, 2017
@poikilotherm poikilotherm deleted the feature_package_json branch October 5, 2017 11:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants