Skip to content

Commit

Permalink
[npm] Fix npm prompt failure when parsing malformed package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimir-kotikov committed Oct 24, 2015
1 parent 1e82695 commit 1cea322
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions npm.lua
Expand Up @@ -186,7 +186,11 @@ function npm_prompt_filter()
local package_info = package:read('*a')
package:close()
local package_name = string.match(package_info, '"name"%s*:%s*"(.-)"')
or "<invalid_name>"

local package_version = string.match(package_info, '"version"%s*:%s*"(.-)"')
or "<invalid_version>"

local package_string = color.color_text("("..package_name.."@"..package_version..")", color.YELLOW)
clink.prompt.value = clink.prompt.value:gsub('{git}', '{git} '..package_string)
end
Expand Down

3 comments on commit 1cea322

@daniloesser
Copy link

Choose a reason for hiding this comment

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

Thanks for the tip ! I've applied some logic operators to avoid error messages in PHPStorm terminal:

    if package_version== nil  then
        package_version='' 
    end --if

    if package_name== nil  then
        package_name='' 
    end --if

@Katuva
Copy link

@Katuva Katuva commented on 1cea322 Feb 28, 2016

Choose a reason for hiding this comment

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

I'd rather not see the npm prompt at all, so I did:

local package_string = ""

if package_name ~= nil and package_version ~= nil then
    package_string = color.color_text("("..package_name.."@"..package_version..")", color.YELLOW)
end

@aplocher
Copy link

Choose a reason for hiding this comment

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

Prefer Katuva's solution. Mine was still having problems until I added that if-statement. Plus having it say "<INVALID_VERSION>" kinda sucks.

Please sign in to comment.