Skip to content

Commit

Permalink
fix: compiler with --release induced issue
Browse files Browse the repository at this point in the history
  • Loading branch information
elbywan committed Feb 4, 2024
1 parent 93d5416 commit 18525da
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/commands/install/protocol/file/file.cr
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ struct Zap::Commands::Install::Protocol::File < Zap::Commands::Install::Protocol
def self.normalize?(str : String, path_info : PathInfo?) : {String?, String?}?
return nil unless path_info
path_str = path_info.path.to_s

if path_info.dir?
# npm install <folder>
return "file:#{path_info.relative_path}", nil
Expand Down
2 changes: 2 additions & 0 deletions src/commands/install/protocol/git/git.cr
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ struct Zap::Commands::Install::Protocol::Git < Zap::Commands::Install::Protocol:
# <git remote url>
# <githubname>/<githubrepo>[#<commit-ish>]
return str, nil
else
return nil
end
end

Expand Down
4 changes: 2 additions & 2 deletions src/commands/install/protocol/protocol.cr
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ require "./workspace"
module Zap::Commands::Install::Protocol
Log = Zap::Log.for(self)

PROTOCOLS = [
PROTOCOLS = {
Protocol::Workspace,
Protocol::Alias,
Protocol::File,
Protocol::Git,
Protocol::TarballUrl,
Protocol::Registry,
]
}
end
4 changes: 2 additions & 2 deletions src/commands/install/protocol/registry/registry.cr
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ struct Zap::Commands::Install::Protocol::Registry < Zap::Commands::Install::Prot
def self.normalize?(str : String, path_info : PathInfo?) : {String?, String?}?
parts = str.split('@')
if parts.size == 1 || (parts.size == 2 && str.starts_with?('@'))
return nil, str
return {nil, str}
else
return parts.last, parts[...-1].join('@')
return {parts.last, parts[...-1].join('@')}
end
end

Expand Down
9 changes: 5 additions & 4 deletions src/commands/install/resolver.cr
Original file line number Diff line number Diff line change
Expand Up @@ -355,11 +355,12 @@ module Zap::Commands::Install::Resolver
# See: https://docs.npmjs.com/cli/v9/commands/npm-install?v=true#description
# Returns a {version, name} tuple
private def self.parse_new_package(cli_input : String, *, directory : String) : {String?, String?}
result = Protocol::PROTOCOLS.reduce(nil) do |acc, protocol|
next acc unless acc.nil?
next protocol.normalize?(cli_input, Protocol::PathInfo.from_str(cli_input, directory))
result = nil
Protocol::PROTOCOLS.each do |protocol|
result = protocol.normalize?(cli_input, Protocol::PathInfo.from_str(cli_input, directory))
break if result && (result[0] || result[1])
end
raise "Could not parse #{cli_input}" unless result
raise "Could not parse #{cli_input}" if result.nil? || (result[0].nil? && result[1].nil?)
result
end
end

0 comments on commit 18525da

Please sign in to comment.