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

npm_prompt.lua:11: attempt to concatenate local 'package_version' (a nil value) #700

Closed
shiroming opened this issue Nov 9, 2015 · 36 comments
Labels
👆 clink-completions Upstream issue in clink-completions.

Comments

@shiroming
Copy link

I use webstorm create a react starter kit project.

E:\code
-> cd react\

C:\cmder/vendor/clink-completions/npm_prompt.lua:11: attempt to concatenate local 'package_version' (a nil value)
E:\code\react {git}{hg}
{lamb}

qq 20151109112951

@vladimir-kotikov
Copy link
Contributor

@shiroming, this was fixed in upstream, the fix will be available in Cmder 1.3.0.

At this time you cant try to apply vladimir-kotikov/clink-completions@1cea322 manually to your npm_prompt.lua

@MartiUK MartiUK modified the milestone: 1.3 Nov 9, 2015
@MartiUK MartiUK added 👆 clink-completions Upstream issue in clink-completions. known error labels Nov 9, 2015
@shiroming
Copy link
Author

got it。
THX

There's no wrong information now. Will show

E:\
-> cd code\react\

E:\code\react  (<invalid_name>@<invalid_version>)
->

package.json

{
  "private": true,
  "engines": {
    "node": ">=4.1 <5",
    "npm": ">=3.1 <4"
  },
  "dependencies": {
    "babel-core": "5.8.29",
    "bluebird": "3.0.5",
    "classnames": "2.2.0",
    "eventemitter3": "1.1.1",
    "express": "4.13.3",
    "fastclick": "1.0.6",
    "fbjs": "0.4.0",
    "flux": "2.1.1",
    "front-matter": "2.0.0",
    "history": "1.13.0",
    "jade": "1.11.0",
    "normalize.css": "3.0.3",
    "react": "0.14.2",
    "react-dom": "0.14.2",
    "react-routing": "0.0.5",
    "source-map-support": "0.3.3",
    "superagent": "1.4.0"
  },
  "devDependencies": {
    "autoprefixer": "^6.1.0",
    "babel": "^5.8.29",
    "babel-eslint": "^4.1.4",
    "babel-loader": "^5.3.2",
    "babel-plugin-react-transform": "^1.1.1",
    "browser-sync": "^2.9.12",
    "css-loader": "^0.22.0",
    "csscomb": "^3.1.8",
    "del": "^2.0.2",
    "eslint": "^1.8.0",
    "eslint-config-airbnb": "0.1.0",
    "eslint-loader": "^1.1.1",
    "eslint-plugin-react": "^3.7.1",
    "file-loader": "^0.8.4",
    "gaze": "^0.5.2",
    "git-repository": "^0.1.1",
    "glob": "^5.0.15",
    "jest-cli": "^0.7.1",
    "jscs": "^2.5.0",
    "lodash.merge": "^3.3.2",
    "mkdirp": "^0.5.1",
    "ncp": "^2.0.0",
    "postcss": "^5.0.10",
    "postcss-cssnext": "^2.2.0",
    "postcss-import": "^7.1.3",
    "postcss-loader": "^0.7.0",
    "postcss-nested": "^1.0.0",
    "psi": "^1.0.6",
    "react-transform-catch-errors": "^1.0.0",
    "react-transform-hmr": "^1.0.1",
    "redbox-react": "^1.1.1",
    "replace": "^0.3.0",
    "style-loader": "^0.13.0",
    "url-loader": "^0.5.6",
    "webpack": "^1.12.3",
    "webpack-dev-middleware": "^1.2.0",
    "webpack-hot-middleware": "^2.4.1"
  },
  "jest": {
    "rootDir": "./src",
    "scriptPreprocessor": "../preprocessor.js",
    "unmockedModulePathPatterns": [
      "fbjs",
      "react"
    ]
  },
  "scripts": {
    "lint": "eslint src tools && jscs src tools",
    "csslint": "csscomb src/components --lint --verbose",
    "csscomb": "csscomb src/components --verbose",
    "test": "eslint src && jest",
    "clean": "babel-node tools/run clean",
    "copy": "babel-node tools/run copy",
    "bundle": "babel-node tools/run bundle",
    "build": "babel-node tools/run build",
    "deploy": "babel-node tools/run deploy",
    "serve": "babel-node tools/run serve",
    "start": "babel-node tools/run start"
  }
}

@vladimir-kotikov
Copy link
Contributor

Yup, everything is correct. Your package.json is missing name and version attributes. (probably because it is a templete and you need to add them manually). See package.json reference here

@shiroming
Copy link
Author

OK,I add "name" and "version" manually.

@vladimir-kotikov
Copy link
Contributor

@MartiUK , @Stanzilla, this probably could be closed.

@adiachenko
Copy link

@vladimir-kotikov But what if I use npm just for pulling in dependencies with private property in package.json set to true? This new prompt is kind of obtrusive. You may consider replacing <invalid_name> and <invalid_version> with empty string in npm_prompt.lua.

@vladimir-kotikov
Copy link
Contributor

@adiachenko, actually i'm inclined to replace invalid_ -> no_. This would be more appropriate (and less obtrusive 😄 ), than invalid_ or just empty strings (which would give you e.g. @0.0.1 - looks kinda weird). Or, probably remove npm package badge at all if there is neither package name nor version specified.

@jpruiz114
Copy link

Hi. I'm a little lost here. Got the same issue with a Laravel project under PHPStorm.

Got this message:

C:\cmder/vendor/clink-completions/npm_prompt.lua:11: attempt to concatenate local 'package_version' )e

What approach did you use to solve it?

@vladimir-kotikov
Copy link
Contributor

@jpruiz114, take a look at the 2nd comment on this thread and apply that change to your C:\cmder/vendor/clink-completions/npm_prompt.lua

@jpruiz114
Copy link

Hey @vladimir-kotikov thanks for your message. I'm a little confused here because there are two files:

npm.lua and npm_prompt.lua

In your fix from here:

vladimir-kotikov/clink-completions@1cea322

... you were applying a patch to npm.lua including the function inside npm_prompt.lua

I tried adding the code to both files but still got the weird message:

image

Thanks in advance for your help!

@Stanzilla
Copy link
Member

check your cmder\vendor dir, the only lua file in there should be clink.lua if you have any extra, delete those and try again.

@vladimir-kotikov
Copy link
Contributor

@Stanzilla, why clean cmder/vendor? I think first we need to ask @jpruiz114, which version he uses?

@jpruiz114, you need to add changes to npm_prompt.lua only. In my patch i added them to npm.lua instead because at some point i decided to merge these two files into one. However latest public Cmder version (1.2.9) doesn't include this merge yet.

@Stanzilla
Copy link
Member

@vladimir-kotikov because we changed around what is in there and when users upgrade by just copying the new files into the folder, some old stuff stays around and causes problems like the lambda not showing up because clink was called twice etc, that's why I like to make sure people only have the one lua file there that is actually used at the moment. But I guess it was not the case here.

@ghiscoding
Copy link

hey guys, just to let you know that I actually found another solution that worked from a Chinese blog.

I was getting this

c:\cmder/vendor/clink-completions/npm_prompt.lua:11: attempt to concatenate local 'package_version' (a nil value)

The original npm_prompt.lua was (BEFORE FIX)

...
local package_name = string.match(package_info, '"name"%s*:%s*"(%g-)"')
local package_version = string.match(package_info, '"version"%s*:%s*"(.-)"')
...

and the change is (AFTER FIX):

...
local package_name = string.match(package_info, '"name"%s*:%s*"(%g-)"')
if package_name == nil then
    package_version = ''
end     
local package_version = string.match(package_info, '"version"%s*:%s*"(.-)"')
if package_version == nil then
    package_version = ''
end     

@PancakeTornado
Copy link

@ghiscoding The fix you found has a bug where it does not set package_name

The solution that worked for me was to edit the file:
{YOUR_PATH}/cmder/vendor/clink-completions/npm_prompt.lua
and overwrite the related lines to be this instead:

...
local package_name = string.match(package_info, '"name"%s*:%s*"(%g-)"')
if package_name == nil then
    package_name = ''
end     
local package_version = string.match(package_info, '"version"%s*:%s*"(.-)"')
if package_version == nil then
    package_version = ''
end
...

@eugenesvk
Copy link

I would suggest one additional change to get rid of the stray @ character when there is no version present — adding an additional variable package_version_separator and making it blank '' when there is no version

        local package_version_separator = '@'
        local package_name = string.match(package_info, '"name"%s*:%s*"(%g-)"')
        if package_name == nil then
            package_name = ''
        end
        local package_version = string.match(package_info, '"version"%s*:%s*"(.-)"')
        if package_version == nil then
            package_version = ''
            package_version_separator = ''
        end
        local package_string = color.color_text("("..package_name..package_version_separator..package_version..")", color.YELLOW)

@pantox
Copy link

pantox commented Apr 1, 2016

Thanks all for your inspiration.

If you feel comfortable to have an automatic check for the right version and name field of your package.json leave it as it is. Otherwise for me it feels right when there is no package_name and package_version it shouldn't display anything.

This is my modification of cmder\vendor\clink-completions\npm.lua to get rid of all the empty brackets, symbols and stuff.

function npm_prompt_filter()
    local package = io.open('package.json')
    if package ~= nil then
        local package_info = package:read('*a')
        package:close()
        local package_name = string.match(package_info, '"name"%s*:%s*"(.-)"')
            or ""

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

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

    end
    return false
end

Tested with cmder version v1.2.9

Update in v1.3.0-pre

you have to comment out the last line clink.prompt.register_filter(npm_promt_filter, 40) in ´npm.lua´, as a default behaviour will clink display the name and or the version when its provided in the package.json file.

@dbritto-dev
Copy link

dbritto-dev commented Jun 6, 2016

npm_prompt.lua (v1.2.9)

local color = require('color')

function npm_prompt_filter()
    local package = io.open('package.json')
    if package ~= nil then
        local package_info = package:read('*a')
        package:close()
        local package_private = string.match(package_info, '"private"%s*:%s*true')
        if package_private == nil then
            local package_name = string.match(package_info, '"name"%s*:%s*"(%g-)"')
            local package_version = string.match(package_info, '"version"%s*:%s*"(.-)"')
            local package_string = color.color_text("("..package_name.."@"..package_version..")", color.YELLOW)
            clink.prompt.value = clink.prompt.value:gsub('{git}', '{git} '..package_string)
        end
    end
    return false
end

clink.prompt.register_filter(npm_prompt_filter, 40)

@dbritto-dev
Copy link

If private, u don't need the name or version !!

@visualcookie
Copy link

Can confirm this issue is happening to me right now. Just upgraded to the latest version.

@carlosflorencio
Copy link

Yep me too!

@visualcookie did you fixed it?

@visualcookie
Copy link

@iamfreee Yeah, just copy and pasted @danilobrinu solution and now it works again.

@mcsmithers
Copy link

Hi, I am getting the same error now and the previous fixes seem to not work on this. Do you have any suggestions?

@dbritto-dev
Copy link

@csmithersslc i can help you, i fixed the previous version :)

@mcsmithers
Copy link

@danilobrinu Thank you!

@dbritto-dev
Copy link

@csmithersslc tell me about your issues. Post prints and tag me.

@mcsmithers
Copy link

mcsmithers commented Oct 31, 2016

Sure @danilobrinu

I cd'ed into a new directory and this was the output:
capture

The npm_prompt file reads as @pantox's on Apr 1st.

And the npm one is as follows:
`function npm_prompt_filter()
local package = io.open('package.json')
if package ~= nil then
local package_info = package:read('a')
package:close()
local package_name = string.match(package_info, '"name"%s
:%s*"(.-)"')
or ""

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

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

end
return false

end`

@dbritto-dev
Copy link

dbritto-dev commented Oct 31, 2016

@csmithersslc what is your cmder version ?? u can use this code

function npm_prompt_filter()
    local package = io.open('package.json')
    if package ~= nil then
        local package_info = package:read('*a')
        package:close()
        local package_private = string.match(package_info, '"private"%s*:%s*true')
        if package_private == nil then
            local package_name = string.match(package_info, '"name"%s*:%s*"(%g-)"')
            local package_version = string.match(package_info, '"version"%s*:%s*"(.-)"')
            local package_string = color.color_text("("..package_name.."@"..package_version..")", color.YELLOW)
            clink.prompt.value = clink.prompt.value:gsub('{git}', '{git} '..package_string)
        end
    end
    return false
end

@mcsmithers
Copy link

Wow, that worked perfectly.

I show it is version 161022 stable, the newest version.

Thank you so much!

@dbritto-dev
Copy link

@csmithersslc you can try this code ?

function npm_prompt_filter()
    local package_file = io.open('package.json')

    if package_file then
        local package_data = package_file:read('*a')
        local package = JSON:decode(package_data)

        if package then
             if not package.private then
                local package_name = package.name or "<no name>" 
                local package_version = package.version and "@"..package.version or ""
                local package_string = color.color_text("("..package_name..package_version..")", color.YELLOW)

                clink.prompt.value = clink.prompt.value:gsub('{git}', '{git} '..package_string)
            end
        end
    end

    package_file:close()

    return false
end

@mcsmithers
Copy link

I have tried it and it worked! Thank you for your help.

On Sun, Nov 6, 2016 at 10:58 AM, Danilo Britto Nuñez <
notifications@github.com> wrote:

@csmithersslc https://github.com/csmithersslc you can try this code ?

function npm_prompt_filter()
local package_file = io.open('package.json')

if package_file then
    local package_data = package_file:read('*a')
    local package = JSON:decode(package_data)

    if package then
         if not package.private then
            local package_name = package.name or "<no name>"
            local package_version = package.version and "@"..package.version or ""
            local package_string = color.color_text("("..package_name..package_version..")", color.YELLOW)

            clink.prompt.value = clink.prompt.value:gsub('{git}', '{git} '..package_string)
        end
    end
end

package_file:close()

return falseend


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#700 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AFUmv8qQFMP4Nr9rfx9lgYk69lhaDo-Kks5q7hU0gaJpZM4GeUZU
.

@dbritto-dev
Copy link

@csmithersslc the new version of cmder have fixed, update your cmder o download the latest version :)

@mcsmithers
Copy link

All done. Everything looks good :)

On Sun, Nov 6, 2016 at 2:05 PM, Danilo Britto Nuñez <
notifications@github.com> wrote:

@csmithersslc https://github.com/csmithersslc the new version of cmder
have fixed, update your cmder o download the latest version :)


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#700 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AFUmv6_vqfsoVdOfwgAMhT5GGTBL7ryUks5q7kEQgaJpZM4GeUZU
.

@SixBytesUnder
Copy link

Hi @danilobrinu
I've been having the same issue for months now. I tried to paste the code you gave @csmithersslc but it didn't work for me :(
I get the following error:
screenshot_12

My npm_prompt.lua file looks like this:

local color = require('color')

function npm_prompt_filter()
    local package = io.open('package.json')
    if package ~= nil then
        local package_info = package:read('*a')
        package:close()
        local package_name = string.match(package_info, '"name"%s*:%s*"(%g-)"')
        local package_version = string.match(package_info, '"version"%s*:%s*"(.-)"')
        local package_string = color.color_text("("..package_name.."@"..package_version..")", color.YELLOW)
        clink.prompt.value = clink.prompt.value:gsub('{git}', '{git} '..package_string)
    end
    return false
end

clink.prompt.register_filter(npm_prompt_filter, 40)

Just today updated cmder to version 161206 stable.
How can I fix that?

@dbritto-dev
Copy link

dbritto-dev commented Dec 8, 2016

@6bytes download the lastest version of cmder, that issue is fixed. The version of cmder is 1.3.1 not 161206, 1061206 is the version of ConEmu i recommend not update the ConEmu why is probably not compatible with the lastest version of cmder.

@SixBytesUnder
Copy link

Thank you @danilobrinu I just downloaded latest version and it's all working fine :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
👆 clink-completions Upstream issue in clink-completions.
Projects
None yet
Development

No branches or pull requests