diff --git a/plugins/nodejs/nodejs.go b/plugins/nodejs/nodejs.go index e5a4721..675fcf4 100644 --- a/plugins/nodejs/nodejs.go +++ b/plugins/nodejs/nodejs.go @@ -65,11 +65,6 @@ func (node Node) Events() *emission.Emitter { func (node Node) PostInstall() (err error) { node.Emitter.Emit("postinstall") - ok, err := node.Yarn() - if err != nil && ok == false { - return errors.New(err) - } - return nil } diff --git a/plugins/nodejs/yarn.go b/plugins/nodejs/yarn.go deleted file mode 100644 index eb975e9..0000000 --- a/plugins/nodejs/yarn.go +++ /dev/null @@ -1,86 +0,0 @@ -package nodejs - -import ( - "errors" - "fmt" - "os" - "path/filepath" - - "github.com/blang/semver" - "github.com/markelog/archive" - "github.com/markelog/cprf" - "gopkg.in/cavaliercoder/grab.v1" - - "github.com/markelog/eclectica/io" - "github.com/markelog/eclectica/variables" -) - -var ( - minimalForYarn, _ = semver.Make("6.0.0") - version = "1.22.11" - yarnURL = fmt.Sprintf( - "https://yarnpkg.com/downloads/%s/yarn-v%s.tar.gz", - version, - version, - ) -) - -func (node Node) download(path string) (err error) { - _, err = grab.Get(path, yarnURL) - if err != nil { - return - } - - return -} - -func (node Node) isYarnPossible() bool { - version, _ := semver.Make(node.Version) - - return version.GTE(minimalForYarn) -} - -// Yarn does everything that needs to be done to install yarn -func (node Node) Yarn() (ok bool, err error) { - var ( - path = variables.Path("node", node.Version) - modules = filepath.Join(path, "lib/node_modules") - archived = filepath.Join(variables.TempDir(), "yarn-archived") - unarchived = filepath.Join(variables.TempDir(), "yarn-unarchived") - from = filepath.Join(unarchived, fmt.Sprintf("yarn-v%s/", version)) - dest = filepath.Join(modules, "yarn") - ) - - if node.isYarnPossible() == false { - return true, errors.New("\"" + node.Version + "\" version is not supported by yarn") - } - - if _, statErr := os.Stat(from); statErr != nil { - err = node.download(archived) - if err != nil { - return - } - - err = archive.Extract(archived, unarchived) - if err != nil { - return - } - } - - err = cprf.Copy(from+"/", dest) - if err != nil { - return - } - - os.RemoveAll(archived) - - current := filepath.Join(modules, "yarn/bin/yarn.js") - base := filepath.Join(path, "bin/yarn") - - err = io.Symlink(base, current) - if err != nil { - return - } - - return true, nil -} diff --git a/plugins/nodejs/yarn_test.go b/plugins/nodejs/yarn_test.go deleted file mode 100644 index 25ea46f..0000000 --- a/plugins/nodejs/yarn_test.go +++ /dev/null @@ -1,92 +0,0 @@ -package nodejs_test - -import ( - "os" - - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - - "github.com/markelog/archive" - "github.com/markelog/cprf" - "github.com/markelog/monkey" - "gopkg.in/cavaliercoder/grab.v1" - - "github.com/markelog/eclectica/io" - . "github.com/markelog/eclectica/plugins/nodejs" - "github.com/markelog/eclectica/variables" -) - -var _ = Describe("yarn", func() { - var ( - grabGet bool - archiveExtract bool - cprfCopy bool - ioSymlink bool - ) - - BeforeEach(func() { - grabGet = false - archiveExtract = false - cprfCopy = false - ioSymlink = false - - monkey.Patch(grab.Get, func(path, url string) (*grab.Response, error) { - grabGet = true - return nil, nil - }) - - monkey.Patch(archive.Extract, func(from, to string) error { - archiveExtract = true - return nil - }) - - monkey.Patch(cprf.Copy, func(from, to string) error { - cprfCopy = true - return nil - }) - - monkey.Patch(io.Symlink, func(from, to string) error { - ioSymlink = true - return nil - }) - }) - - AfterEach(func() { - monkey.Unpatch(grab.Get) - monkey.Unpatch(archive.Extract) - monkey.Unpatch(cprf.Copy) - monkey.Unpatch(io.Symlink) - }) - - It("should not try to install yarn for unsupported node version", func() { - working, err := (&Node{Version: "0.10.0"}).Yarn() - - Expect(grabGet).To(Equal(false)) - Expect(archiveExtract).To(Equal(false)) - Expect(cprfCopy).To(Equal(false)) - Expect(ioSymlink).To(Equal(false)) - - Expect(working).To(Equal(true)) - Expect(err.Error()).To(Equal("\"0.10.0\" version is not supported by yarn")) - }) - - It("installs yarn", func() { - monkey.Patch(variables.TempDir, func() string { - path, _ := os.Getwd() - - return path - }) - - working, err := (&Node{Version: "6.10.0"}).Yarn() - - Expect(grabGet).To(Equal(true)) - Expect(archiveExtract).To(Equal(true)) - Expect(cprfCopy).To(Equal(true)) - Expect(ioSymlink).To(Equal(true)) - - Expect(working).To(Equal(true)) - Expect(err).To(BeNil()) - - monkey.Unpatch(variables.TempDir()) - }) -})