-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* allow @ sign in range. Fix failing git parse unit test. restructure. * update README * remove trace statement * % -> @
- Loading branch information
Showing
10 changed files
with
121 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,7 +81,7 @@ it immediately with `nix-build`. | |
|
||
```bash | ||
$ git clone https://github.com/adnelson/nix-node-packages | ||
$ nixfromnpm -o nix-node-packages -p 'the-package-I-need%the-version-I-need' | ||
$ nixfromnpm -o nix-node-packages -p 'the-package-I-need@the-version-I-need' | ||
$ nix-build nix-node-packages -A nodePackages.the-package-I-need_the-version-I-need | ||
``` | ||
|
||
|
@@ -105,22 +105,20 @@ output path does exist, a package will only be fetched if a nix | |
expression for it doesn't already exist. | ||
|
||
You can also specify a version bound on the packages you are fetching, | ||
using `%`: | ||
using `@`: | ||
|
||
```bash | ||
$ nixfromnpm -p package_name%version_bound -o /some/path | ||
$ nixfromnpm -p package_name@version_bound -o /some/path | ||
``` | ||
|
||
Any NPM version bound is valid; so for example: | ||
|
||
```bash | ||
$ nixfromnpm -p foo%0.8.6 -o /some/path | ||
$ nixfromnpm -p 'foo%>=0.8 <0.9' -o /some/path | ||
$ nixfromnpm -p 'foo%~1.0.0' -o /some/path | ||
$ nixfromnpm -p foo@0.8.6 -o /some/path | ||
$ nixfromnpm -p 'foo@>=0.8 <0.9' -o /some/path | ||
$ nixfromnpm -p 'foo@~1.0.0' -o /some/path | ||
``` | ||
|
||
(Note that we're using a `%` instead of a `@` to indicate a version range). | ||
|
||
#### Generating an expression from a package.json file | ||
|
||
You can also generate an expression for a project on the local disk by | ||
|
@@ -249,7 +247,7 @@ the most common ones are: | |
* See what version range `nixfromnpm` failed to resolve. E.g. `foo@>=1.2.3-bar <2.3.4-baz.qux`. | ||
* Use `npm` to manually build the package at the given version bounds. E g. `npm install foo@>=1.2.3-bar <2.3.4-baz.qux`. | ||
* See what version it ends up building. E.g. `[email protected]`. | ||
* Call `nixfromnpm` on that version. E.g. `nixfromnpm -o /path/to/nix-node-packages -p 'foo%1.2.3-xyz'`. | ||
* Call `nixfromnpm` on that version. E.g. `nixfromnpm -o /path/to/nix-node-packages -p 'foo@1.2.3-xyz'`. | ||
* Replace the call to `brokenPackage` with `foo_1-2-3-xyz`. | ||
* The build fails with `npm` complaining about HTTP errors. This is usually caused by a dependency that wasn't satified, likely because `nixfromnpm` calculated the wrong dependency. In this case, use steps similar to the above to find out what the actual dependency should be, and modify the package definition to include the correct one. | ||
* A package build script is attempting to do some hacky bullshit like modifying its dependencies. This, of course, is not kosher in the `nix` view of things. In this case, you'll probably want to `nix-shell` into the package and see what it's trying to do. Figure out how to stop it from doing these things, and supply `prePatch` or `postPatch` steps to apply those changes. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,9 @@ | ||
{-# LANGUAGE QuasiQuotes #-} | ||
{-# LANGUAGE NoImplicitPrelude #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
module Main where | ||
|
||
import qualified Options.Applicative as O | ||
import System.Environment (getArgs) | ||
import System.Exit | ||
import System.Exit (exitWith) | ||
|
||
import NixFromNpm.Common hiding (getArgs) | ||
import NixFromNpm.Options (NixFromNpmOptions, parseOptions, | ||
validateOptions) | ||
import NixFromNpm.Conversion.ToDisk (dumpPkgFromOptions) | ||
import NixFromNpm.Merge (mergeInto, MergeType(..), Source(..), Dest(..)) | ||
|
||
customExecParser_ :: O.ParserInfo a -> [String] -> IO a | ||
customExecParser_ pinfo args = do | ||
let result = O.execParserPure O.defaultPrefs pinfo args | ||
O.handleParseResult result | ||
|
||
mainFromArgs :: [String] -> IO a | ||
mainFromArgs args = do | ||
let pInfo = O.info (O.helper <*> parseOptions) | ||
(O.fullDesc <> O.progDesc description <> O.header headerText) | ||
|
||
parsedOpts <- customExecParser_ pInfo args | ||
validatedOpts <- validateOptions parsedOpts | ||
exitWith =<< dumpPkgFromOptions validatedOpts | ||
where | ||
description = concat ["nixfromnpm allows you to generate nix expressions ", | ||
"automatically from npm packages. It provides ", | ||
"features such as de-duplication of shared ", | ||
"dependencies and advanced customization."] | ||
headerText = "nixfromnpm - Create nix expressions from NPM" | ||
import NixFromNpm.Cli (runWithArgs) | ||
|
||
main :: IO () | ||
main = mainFromArgs =<< getArgs | ||
main = exitWith =<< runWithArgs =<< getArgs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
-- | The nixfromnpm command-line interface | ||
{-# LANGUAGE NoImplicitPrelude #-} | ||
module NixFromNpm.Cli (runWithArgs) where | ||
|
||
import qualified Options.Applicative as O | ||
import System.Environment (getArgs) | ||
import System.Exit (ExitCode) | ||
|
||
import NixFromNpm.Common hiding (getArgs) | ||
import NixFromNpm.Options (NixFromNpmOptions, parseOptions, | ||
validateOptions) | ||
import NixFromNpm.Conversion.ToDisk (dumpPkgFromOptions) | ||
import NixFromNpm.Merge (mergeInto, MergeType(..), Source(..), Dest(..)) | ||
|
||
-- | Execute an argument parser with a list of arguments. | ||
customExecParser_ :: O.ParserInfo a -> [String] -> IO a | ||
customExecParser_ pinfo args = do | ||
let result = O.execParserPure O.defaultPrefs pinfo args | ||
O.handleParseResult result | ||
|
||
-- | Execute the CLI with an argument list, returning an exit code. | ||
runWithArgs :: [String] -> IO ExitCode | ||
runWithArgs args = do | ||
let pInfo = O.info (O.helper <*> parseOptions) | ||
(O.fullDesc <> O.progDesc description <> O.header headerText) | ||
|
||
parsedOpts <- customExecParser_ pInfo args | ||
validatedOpts <- validateOptions parsedOpts | ||
dumpPkgFromOptions validatedOpts | ||
where | ||
description = concat ["nixfromnpm allows you to generate nix expressions ", | ||
"automatically from npm packages. It provides ", | ||
"features such as de-duplication of shared ", | ||
"dependencies and advanced customization."] | ||
headerText = "nixfromnpm - Create nix expressions from NPM" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ import qualified Data.Text as T | |
|
||
import NixFromNpm | ||
import NixFromNpm.Git.Types as Git | ||
import NixFromNpm.Npm.PackageMap (PackageName(..)) | ||
import NixFromNpm.Npm.Version as Npm | ||
|
||
shouldBeR :: (Eq a, Eq b, Show a, Show b) => Either a b -> b -> Expectation | ||
|
@@ -82,7 +83,30 @@ npmVersionParserSpec = describe "npm version parser" $ do | |
parseNpmVersionRange "../foo/bar" `shouldBeJ` LocalPath "../foo/bar" | ||
parseNpmVersionRange "~/foo/bar" `shouldBeJ` LocalPath "~/foo/bar" | ||
|
||
npmNameAndVersionParserSpec :: Spec | ||
npmNameAndVersionParserSpec = describe "npm name@version parser" $ do | ||
it "should parse a name with no version range" $ do | ||
(name, range) <- parseNameAndRange "foo" | ||
name `shouldBe` "foo" | ||
range `shouldBe` SemVerRange anyVersion | ||
|
||
it "should parse a namespaced name with no version range" $ do | ||
(name, range) <- parseNameAndRange "@foo/bar" | ||
name `shouldBe` PackageName "bar" (Just "foo") | ||
range `shouldBe` SemVerRange anyVersion | ||
|
||
it "should parse a name and a version range" $ do | ||
(name, range) <- parseNameAndRange "[email protected]" | ||
name `shouldBe` "foo" | ||
range `shouldBe` SemVerRange (Eq $ semver 1 2 3) | ||
|
||
it "should parse a namespaced name and a version range" $ do | ||
(name, range) <- parseNameAndRange "@foo/[email protected]" | ||
name `shouldBe` PackageName "bar" (Just "foo") | ||
range `shouldBe` SemVerRange (Eq $ semver 1 2 3) | ||
|
||
main :: IO () | ||
main = hspec $ do | ||
-- npmVersionParserSpec | ||
npmVersionParserSpec | ||
npmNameAndVersionParserSpec | ||
gitIdParsingSpec |