vapor/toolbox

vapor --version couldn't work correctly

PainTypeZ opened this issue · 7 comments

Describe the bug

when I follow this steps in vapor documentation:
#verify we are in vapor project folder
vapor --version

terminal shows:

vapor --version
note: no Package.resolved file was found. Possibly not currently in a Swift package directory
framework: Vapor framework for this project: no Package.resolved file found. Please ensure you are in a Vapor project directory. If you are, ensure you have built the project with swift build. You can create a new project with vapor new MyProject
toolbox: 18.5.1

To Reproduce

just follow the Vapor Docs Getting Started steps.

Expected behavior

the terminal should show:
framework: 4.x.x
toolbox: 18.x.x

Environment

  • Vapor Framework version: 4.65.1
  • Vapor Toolbox version: 18.5.1
  • OS version: macOS Monterey 12.5.1
  • Xcode version: 13.4.1 (13F100)

Additional context

swift build or Xcode build & run works fine. Already tried to create a new hello project and create a new MyProject, both couldn't show vapor framework version.

I created hello project with terminal command vapor new hello -n.

vzsg commented

Where exactly do you see that command in the documentation? I scrolled through the Install/Getting Started/Basics pages at docs.vapor.codes but don't see any reference to the vapor version toolbox command (anymore).

And have you tried following the error message, i.e. running swift build?
(Or even a swift package resolve would create the file it's missing.)

0xTim commented

I also think you're in the wrong directory - ie not the project directory

Where exactly do you see that command in the documentation? I scrolled through the Install/Getting Started/Basics pages at docs.vapor.codes but don't see any reference to the vapor version toolbox command (anymore).

And have you tried following the error message, i.e. running swift build? (Or even a swift package resolve would create the file it's missing.)

thanks for help :)
https://docs.vapor.codes/getting-started/xcode/ in the bottom; I did run swift build or swift package resolve in terminal, it works fine; And Xcode GUI could build & run the "hello" project; The Package.resolved file looks good, Package Dependencies looks good; And I edited Edit Scheme -> Run -> Options -> Working Directory, Use custom working directory with project path. All action were working fine except vapor --version command. It didn't effect code server-side with vapor, but this little problem makes me confused.

here's the terminal action and output:
cd to project =>
pwd confirm path =>
vapor --version get warning note =>
swift build works fine =>
vapor --version get warning note=>
swift package resolve works fine =>
vapor --version get warning note =>
swift run works fine

develop@PTiMac ~ % cd GitRepos 
develop@PTiMac GitRepos % cd hello 
develop@PTiMac hello % pwd            
/Users/develop/GitRepos/hello
develop@PTiMac hello % vapor --version
note: no Package.resolved file was found. Possibly not currently in a Swift package directory
framework: Vapor framework for this project: no Package.resolved file found. Please ensure you are in a Vapor project directory. If you are, ensure you have built the project with `swift build`. You can create a new project with `vapor new MyProject`
toolbox: 18.5.1
develop@PTiMac hello % swift build
Building for debugging...
Build complete! (8.40s)
develop@PTiMac hello % vapor --version
note: no Package.resolved file was found. Possibly not currently in a Swift package directory
framework: Vapor framework for this project: no Package.resolved file found. Please ensure you are in a Vapor project directory. If you are, ensure you have built the project with `swift build`. You can create a new project with `vapor new MyProject`
toolbox: 18.5.1
develop@PTiMac hello % swift package resolve
develop@PTiMac hello % vapor --version
note: no Package.resolved file was found. Possibly not currently in a Swift package directory
framework: Vapor framework for this project: no Package.resolved file found. Please ensure you are in a Vapor project directory. If you are, ensure you have built the project with `swift build`. You can create a new project with `vapor new MyProject`
toolbox: 18.5.1
develop@PTiMac hello % swift run
Building for debugging...
Build complete! (0.33s)
[ NOTICE ] Server starting on http://127.0.0.1:8080
^C
develop@PTiMac hello % 

I also think you're in the wrong directory - ie not the project directory

thanks for help :)
I did in the project directory. check my reply for vzsg.

I also think you're in the wrong directory - ie not the project directory

Hello @0xTim. Could you help transform the issue to vapor/toolbox.

I can confirm this is a bug in vapor/toolbox and I'll open a pull request to fix it.

Line 56 will unexpectly throw an error even if there is a valid Package.resolved file. (If any of the package dependency's version is null eg. local dependency or branch dependency)

image

▿ DecodingError
  ▿ valueNotFound : 2 elements
    - .0 : Swift.String
    ▿ .1 : Context
      ▿ codingPath : 5 elements
        - 0 : CodingKeys(stringValue: "object", intValue: nil)
        - 1 : CodingKeys(stringValue: "pins", intValue: nil)
        ▿ 2 : _JSONKey(stringValue: "Index 6", intValue: 6)
          - stringValue : "Index 6"
          ▿ intValue : Optional<Int>
            - some : 6
        - 3 : CodingKeys(stringValue: "state", intValue: nil)
        - 4 : CodingKeys(stringValue: "version", intValue: nil)
      - debugDescription : "Expected String value but found null instead."
      - underlyingError : nil

private func outputFrameworkVersion(context: CommandContext) {
do {
let packageString = try Process.shell.run("cat", "Package.resolved")
let package = try JSONDecoder().decode(PackageResolved.self, from: .init(packageString.utf8))
if let vapor = package.object.pins.filter({ $0.package == "vapor" }).first {
context.console.output(key: "framework", value: vapor.state.version)
} else {
context.console.output("\("note:", style: .warning) this Swift project does not depend on Vapor.")
context.console.output(key: "framework", value: "Vapor framework for this project: this Swift project does not depend on Vapor. Please ensure you are in a Vapor project directory. If you are, ensure you have built the project with `swift build`. You can create a new project with `vapor new MyProject`")
}
} catch {
context.console.output("\("note:", style: .warning) no Package.resolved file was found. Possibly not currently in a Swift package directory")
context.console.output(key: "framework", value: "Vapor framework for this project: no Package.resolved file found. Please ensure you are in a Vapor project directory. If you are, ensure you have built the project with `swift build`. You can create a new project with `vapor new MyProject`")
}
}

0xTim commented

Ah this is probably the V2 pins we don't handle correctly

Ah this is probably the V2 pins we don't handle correctly

No, it is still v1.