Blacklite / Ncapsulate

NuGet and MSBuild wrappers around various Node based tools.
MIT License
29 stars 9 forks source link

Gulp package generates errors running install script #3

Closed isochronous closed 10 years ago

isochronous commented 10 years ago

Okay, basic details first: This is on Windows Server 2008 R2, using Visual Studio 2013 Professional Update 2, nuget 2.8.50313.46, and I've cleared my nuget package cache. I have the node toolkit for VS2013 installed, as well as the regular old node x64 installer from nodejs.org (with both node and npm on the system path).

The problem occurs when trying to install the Ncapsulate Gulp and Node packages. If I try installing Gulp directly, without installing Ncapsulate.Node first, the install succeeds but I get four errors in the package manager console:

Unable to index into an object of type System.IO.DirectoryInfo.
At D:\Projects\Launch\ai5\MobileConfig\source\packages\Ncapsulate.Node.0.10.26\tools\commands.psm1:5 char:96
+ $nodePath = (Get-ChildItem "$installPath\..\Ncapsulate.Node.*" | Sort-Object Name -descending)[ <<<< 0].FullName;
    + CategoryInfo          : InvalidOperation: (0:Int32) [], RuntimeException
    + FullyQualifiedErrorId : CannotIndex

Unable to index into an object of type System.IO.DirectoryInfo.
At D:\Projects\Launch\ai5\MobileConfig\source\packages\Ncapsulate.Gulp.3.6.2.1\tools\commands.psm1:5 char:96
+ $nodePath = (Get-ChildItem "$installPath\..\Ncapsulate.Node.*" | Sort-Object Name -descending)[ <<<< 0].FullName;
    + CategoryInfo          : InvalidOperation: (0:Int32) [], RuntimeException
    + FullyQualifiedErrorId : CannotIndex

D:\Projects\Launch\ai5\MobileConfig\source\Ai.MobileConfig
..\packages\Ncapsulate.Gulp.3.6.2.1
Unable to index into an object of type System.IO.DirectoryInfo.
At D:\Projects\Launch\ai5\MobileConfig\source\packages\Ncapsulate.Gulp.3.6.2.1\tools\install.ps1:18 char:96
+ $nodePath = (Get-ChildItem "$installPath\..\Ncapsulate.Node.*" | Sort-Object Name -descending)[ <<<< 0].FullName;
    + CategoryInfo          : InvalidOperation: (0:Int32) [], RuntimeException
    + FullyQualifiedErrorId : CannotIndex

Resolve-Path : Cannot bind argument to parameter 'Path' because it is null.
At D:\Projects\Launch\ai5\MobileConfig\source\packages\Ncapsulate.Gulp.3.6.2.1\tools\install.ps1:20 char:33
+ $nodeRelativePath = Resolve-Path <<<<  -Relative $nodePath
    + CategoryInfo          : InvalidData: (:) [Resolve-Path], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ResolvePath 
   Command

If instead I install Ncapsulate.Node via nuget before installing Ncapsulate.Gulp, it installs with one error:

Unable to index into an object of type System.IO.DirectoryInfo.
At D:\Projects\Launch\ai5\MobileConfig\source\packages\Ncapsulate.Node.0.10.26.3\tools\commands.psm1:5 char:96
+ $nodePath = (Get-ChildItem "$installPath\..\Ncapsulate.Node.*" | Sort-Object Name -descending)[ <<<< 0].FullName;
    + CategoryInfo          : InvalidOperation: (0:Int32) [], RuntimeException
    + FullyQualifiedErrorId : CannotIndex

And then installing Ncapsulate.Gulp still produces four errors:

Unable to index into an object of type System.IO.DirectoryInfo.
At D:\Projects\Launch\ai5\MobileConfig\source\packages\Ncapsulate.Node.0.10.26.3\tools\commands.psm1:5 char:96
+ $nodePath = (Get-ChildItem "$installPath\..\Ncapsulate.Node.*" | Sort-Object Name -descending)[ <<<< 0].FullName;
    + CategoryInfo          : InvalidOperation: (0:Int32) [], RuntimeException
    + FullyQualifiedErrorId : CannotIndex

Unable to index into an object of type System.IO.DirectoryInfo.
At D:\Projects\Launch\ai5\MobileConfig\source\packages\Ncapsulate.Gulp.3.6.2.1\tools\commands.psm1:5 char:96
+ $nodePath = (Get-ChildItem "$installPath\..\Ncapsulate.Node.*" | Sort-Object Name -descending)[ <<<< 0].FullName;
    + CategoryInfo          : InvalidOperation: (0:Int32) [], RuntimeException
    + FullyQualifiedErrorId : CannotIndex

D:\Projects\Launch\ai5\MobileConfig\source\Ai.MobileConfig
..\packages\Ncapsulate.Gulp.3.6.2.1
Unable to index into an object of type System.IO.DirectoryInfo.
At D:\Projects\Launch\ai5\MobileConfig\source\packages\Ncapsulate.Gulp.3.6.2.1\tools\install.ps1:18 char:96
+ $nodePath = (Get-ChildItem "$installPath\..\Ncapsulate.Node.*" | Sort-Object Name -descending)[ <<<< 0].FullName;
    + CategoryInfo          : InvalidOperation: (0:Int32) [], RuntimeException
    + FullyQualifiedErrorId : CannotIndex

Resolve-Path : Cannot bind argument to parameter 'Path' because it is null.
At D:\Projects\Launch\ai5\MobileConfig\source\packages\Ncapsulate.Gulp.3.6.2.1\tools\install.ps1:20 char:33
+ $nodeRelativePath = Resolve-Path <<<<  -Relative $nodePath
    + CategoryInfo          : InvalidData: (:) [Resolve-Path], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ResolvePath 
   Command

And finally, the results of all of this. Basically, the node package seems to work fine (at least, npm install is being called, as I can see the task output in the output panel), but the gulp task runner does not - I neither see output nor do the files the task should generate ever appear in the destination folder.

Just in case, here's my gulp.targets file:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Target Name="Gulp-AfterBuild" AfterTargets="AfterBuild">
    <Gulp Tasks="build" />
  </Target>
</Project>

And my node.targets file is absolutely stock:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <!-- Support for Incremental builds -->
  <!-- When package.json is changed, we'll install and update, then update lastrun -->
  <ItemGroup>
    <NpmJson Include="$(MSBuildProjectDirectory)\package.json" />
    <NpmLastRun Include="$(MSBuildProjectDirectory)\node_modules\npm.lastrun" />
  </ItemGroup>
  <Target Name="Npm" BeforeTargets="BeforeBuild" Inputs="@(NpmJson)" Outputs="@(NpmLastRun)">
    <NpmInstall />
    <NpmUpdate />
    <Delete Files="$(MSBuildProjectDirectory)\node_modules\npm.lastrun" />
    <WriteLinesToFile File="$(MSBuildProjectDirectory)\node_modules\npm.lastrun" Lines="" />
  </Target>
  <Target Name="NpmClean" BeforeTargets="BeforeClean">
    <Delete Files="$(MSBuildProjectDirectory)\node_modules\npm.lastrun" />
  </Target>
</Project>

Honestly, this package is AWESOME, and I really want to use it to its full potential, but right now I have no idea what's going wrong or how to go about fixing it.

isochronous commented 10 years ago

This may be similar to #2, as when I look at the gulp.cmd file installed by the package, the path to node seem to be invalid:

@echo off
\nodejs\node ..\packages\Ncapsulate.Gulp.3.6.2.1\nodejs\node_modules\gulp\bin\gulp --no-color %*
@echo on

The node.cmd file, however, has the correct path:

@echo off
..\packages\Ncapsulate.Node.0.10.26.3\nodejs\node %*
@echo on

And once I fixed the bad path to node in gulp.cmd, my <Gulp Tasks="build" /> command started working.

david-driscoll commented 10 years ago

Those errors sound like an outdated powershell (2.0). I'm running Powershell 3.0 so I never noticed that issue.

If possible you could try upgrading to Powershell 3 (I understand this isn't ideal), alternatively I can look into an alternate way of identifying the node package directory in https://github.com/Blacklite/Ncapsulate/blob/master/Ncapsulate.Gulp/tools/install.ps1

I have a feeling the culprit is this line $nodePath = (Get-ChildItem "$installPath\..\Ncapsulate.Node.*" | Sort-Object Name -descending)[0]. FullName;

Essentially what we're trying to do is find the latest Ncapsulate.Node directory, and get it's full name.

I can see later tonight if I have a moment to figure out another way to rewrite that statement to work with powershell 2.0.

Right now I have hungry kids to feed!

david-driscoll commented 10 years ago

I just did a quick test, I can convert $nodePath = (Get-ChildItem "$installPath\..\Ncapsulate.Node.*" | Sort-Object Name -descending)[0].FullName; => $nodePath = (Get-ChildItem "$installPath\..\Ncapsulate.Node.*" | Sort-Object Name -descending).FullName;

After that things magically start to work in Powershell 2.0 and it works for Powershell 3 and 4 as well.

As a side note you can run different versions of powershell using the -version command, the more you know!

I'll see if I can get this sometime tonight.

isochronous commented 10 years ago

Awesome! I didn't even realize there was a new version of powershell to use - I'll do that ASAP. In the meantime, if you could make that change and update the nuget packages, it would be a HUGE help to my team!

david-driscoll commented 10 years ago

Change is up, let me know if you or your team has any more problems!

isochronous commented 10 years ago

Will do, thanks so much!

-----Original Message----- From: "David Driscoll" notifications@github.com Sent: ‎5/‎27/‎2014 10:46 PM To: "Blacklite/Ncapsulate" Ncapsulate@noreply.github.com Cc: "Jeremy McLeod" isochronous@gmail.com Subject: Re: [Ncapsulate] Gulp package generates errors running install script(#3)

Change is up, let me know if you or your team has any more problems! — Reply to this email directly or view it on GitHub.

isochronous commented 10 years ago

This works perfectly. Thanks again!