Skip to content

Commit

Permalink
Support object based dependencies (#139)
Browse files Browse the repository at this point in the history
* support obscure format for specifying dependencies using an object with a "version" key

* add test in circle

* add a comment
  • Loading branch information
adnelson authored Jun 25, 2018
1 parent 5f0033c commit 76775d2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,11 @@ jobs:
cd $(mktemp -d)
nixfromnpm -o output -p '[email protected]'
nix-build output -A nodePackages.sane_2-5-0 --max-jobs 2
- run:
name: Build package which uses an undocumented format for specifying dependencies
command: |
PATH=$(readlink result)/bin:$PATH
cd $(mktemp -d)
nixfromnpm -o output -p deep-diff
nix-build output -A nodePackages.deep-diff --max-jobs 2
13 changes: 13 additions & 0 deletions src/NixFromNpm/Npm/Version.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
module NixFromNpm.Npm.Version where

import qualified Data.Text as T
import qualified Data.HashMap.Strict as H

import Data.SemVer
import Data.Aeson
Expand Down Expand Up @@ -85,6 +86,18 @@ instance FromJSON NpmVersionRange where
String s -> case parseNpmVersionRange s of
Nothing -> return $ InvalidVersion s
Just range -> return range
-- NOTE: I couldn't find a mention of this format for specifying
-- versions in the official package.json documentation. However,
-- this was encountered in the wild:
--
-- https://github.com/adnelson/nixfromnpm/issues/138
--
-- Making a special case for it here seems pretty harmless,
-- especially if it was at one point supported. Alternatively, we
-- could allow parsing dev dependencies and such-like to fail.
Object m -> case H.lookup "version" m of
Just v -> parseJSON v
Nothing -> fail "no 'version' key found in dependency object"
_ -> Aeson.typeMismatch "string" v

-- | A package name can be passed in directly, or a version range can be
Expand Down

0 comments on commit 76775d2

Please sign in to comment.