// InstallPackage installs an npm package.
14570
func (c *Client) InstallPackage(name string) error {
	_, stderr, err := c.execNpm("install", name)
	if err != nil {
		if strings.Contains(stderr, "no such package available") {
			return errors.New("no such package available")
		}
		return errors.New(stderr)
	}
	return nil
}
779602
func (i *Installer) Install() ([]string, error) {
	if len(i.RemoteFiles) == 0 {
		return nil, errNoFilesToInstall
	}

	allErrors := *errors.New("")
	var installedDirectories []string // not strict to the remote file len because it continues on error

	// create a copy of the remote files
	remoteFiles := append([]string{}, i.RemoteFiles...)
	// clear the installers's remote files
	i.mu.Lock()
	i.RemoteFiles = nil

	for _, remoteFileZip := range remoteFiles {
		p, err := Install(remoteFileZip, i.InstallDir, i.Indicator)
		if err != nil {
			allErrors = allErrors.AppendErr(err)
			// add back the remote file if the install of this remote file has failed
			i.RemoteFiles = append(i.RemoteFiles, remoteFileZip)
		}

		installedDirectories = append(installedDirectories, p)
	}
	i.mu.Unlock()
	if !allErrors.IsAppended() {
		return installedDirectories, nil
	}

	return installedDirectories, allErrors
}
461233
func fillPackage(p *build.Package) error {
	var buildPrefix = "// +build "
	var buildFieldSplit = func(r rune) bool {
		return unicode.IsSpace(r) || r == ','
	}

	gofiles, err := filepath.Glob(filepath.Join(p.Dir, "*.go"))
	if err != nil {
		return err
	}

	if len(gofiles) == 0 {
		return &build.NoGoError{Dir: p.Dir}
	}

	var testImports []string
	var imports []string
	for _, file := range gofiles {
		// Skip underscore-led files, in keeping with the rest of the toolchain.
		if filepath.Base(file)[0] == '_' {
			continue
		}
		pf, err := parser.ParseFile(token.NewFileSet(), file, nil, parser.ImportsOnly|parser.ParseComments)
		if err != nil {
			if os.IsPermission(err) {
				continue
			}
			return err
		}
		testFile := strings.HasSuffix(file, "_test.go")
		fname := filepath.Base(file)

		var ignored bool
		for _, c := range pf.Comments {
			if c.Pos() > pf.Package { // +build comment must come before package
				continue
			}

			var ct string
			for _, cl := range c.List {
				if strings.HasPrefix(cl.Text, buildPrefix) {
					ct = cl.Text
					break
				}
			}
			if ct == "" {
				continue
			}

			for _, t := range strings.FieldsFunc(ct[len(buildPrefix):], buildFieldSplit) {
				// hardcoded (for now) handling for the "ignore" build tag
				// We "soft" ignore the files tagged with ignore so that we pull in their imports.
				if t == "ignore" {
					ignored = true
				}
			}
		}

		if testFile {
			p.TestGoFiles = append(p.TestGoFiles, fname)
			if p.Name == "" && !ignored {
				p.Name = strings.TrimSuffix(pf.Name.Name, "_test")
			}
		} else {
			if p.Name == "" && !ignored {
				p.Name = pf.Name.Name
			}
			p.GoFiles = append(p.GoFiles, fname)
		}

		for _, is := range pf.Imports {
			name, err := strconv.Unquote(is.Path.Value)
			if err != nil {
				return err // can't happen?
			}
			if testFile {
				testImports = append(testImports, name)
			} else {
				imports = append(imports, name)
			}
		}
	}

	imports = uniq(imports)
	testImports = uniq(testImports)
	p.Imports = imports
	p.TestImports = testImports
	return nil
}
695556
func (c *Context) ResolvePackage(path string) (*Package, error) {
	if path == "." {
		return nil, errors.Errorf("%q is not a package", filepath.Join(c.Projectdir(), "src"))
	}
	path, err := relImportPath(filepath.Join(c.Projectdir(), "src"), path)
	if err != nil {
		return nil, err
	}
	if path == "." || path == ".." || strings.HasPrefix(path, "./") || strings.HasPrefix(path, "../") {
		return nil, errors.Errorf("import %q: relative import not supported", path)
	}
	return c.loadPackage(nil, path)
}
516218
func LoadPackage(ccname string, ccversion string, path string) (CCPackage, error) {
	return (&CCInfoFSImpl{}).GetChaincodeFromPath(ccname, ccversion, path)
}
682396
func (g *GoParser) parsePackage(directory string, names []string, text interface{}) {
	var files []*File
	var astFiles []*ast.File
	g.Package = new(Package)
	fs := token.NewFileSet()
	for _, name := range names {
		if !strings.HasSuffix(name, ".go") {
			continue
		}
		parsedFile, err := parser.ParseFile(fs, name, text, 0)
		if err != nil {
			log.Fatalf("parsing package: %s: %s", name, err)
		}
		astFiles = append(astFiles, parsedFile)
		files = append(files, &File{
			file: parsedFile,
			pkg:  g.Package,
		})
	}
	if len(astFiles) == 0 {
		log.Fatalf("%s: no buildable Go files", directory)
	}
	g.Package.Name = astFiles[0].Name.Name
	g.Package.files = files
	g.Package.dir = directory
	// Type check the package.
	g.Package.check(fs, astFiles)
}
607999
func (client *Client) CreatePackage(pkg Package) (Package, Warnings, error) {
	bodyBytes, err := json.Marshal(pkg)
	if err != nil {
		return Package{}, nil, err
	}

	request, err := client.newHTTPRequest(requestOptions{
		RequestName: internal.PostPackageRequest,
		Body:        bytes.NewReader(bodyBytes),
	})
	if err != nil {
		return Package{}, nil, err
	}

	var responsePackage Package
	response := cloudcontroller.Response{
		DecodeJSONResponseInto: &responsePackage,
	}
	err = client.connection.Make(request, &response)

	return responsePackage, response.Warnings, err
}
1185096
func (impl *repoImpl) UnhidePackage(c context.Context, r *api.PackageRequest) (*empty.Empty, error) {
	return impl.setPackageHidden(c, r, model.Visible)
}
1013683
func (qc *QueryContext) WithPackage(pkg *Package) *QueryContext {
	if qc == nil {
		qc = NewQueryContext()
	}
	qc.Package = pkg
	return qc
}
429740
func isInPackage(fileName string, pkg string) (bool, error) {
	dir, err := filepath.Abs(filepath.Dir(fileName))
	if err != nil {
		return false, err
	}
	dir = path.Clean(dir)
	pkg = path.Clean(pkg)
	if !strings.HasSuffix(dir, pkg) {
		return false, nil
	}

	src := strings.TrimSuffix(dir, pkg)
	src = path.Clean(src)
	goPaths := strings.Split(os.Getenv("GOPATH"), string(filepath.ListSeparator))
	for _, goPath := range goPaths {
		if filepath.Join(goPath, "src") == src {
			return true, nil
		}
	}
	return false, nil
}
848937
func generatePackage(ctx *context, w *bufio.Writer) error {
	logf("generating package %q", ctx.packageName)

	// generate file header
	generateHeader(ctx, w)
	generateImports(ctx, w)

	if ctx.includeAPIVersionCrc {
		fmt.Fprintf(w, "// %s defines API version CRC of the VPP binary API module.\n", constAPIVersionCrc)
		fmt.Fprintf(w, "const %s = %v\n", constAPIVersionCrc, ctx.packageData.APIVersion)
		fmt.Fprintln(w)
	}

	// generate services
	if len(ctx.packageData.Services) > 0 {
		generateServices(ctx, w, ctx.packageData.Services)

		// TODO: generate implementation for Services interface
	}

	// generate enums
	if len(ctx.packageData.Enums) > 0 {
		fmt.Fprintf(w, "/* Enums */\n\n")

		for _, enum := range ctx.packageData.Enums {
			generateEnum(ctx, w, &enum)
		}
	}

	// generate aliases
	if len(ctx.packageData.Aliases) > 0 {
		fmt.Fprintf(w, "/* Aliases */\n\n")

		for _, alias := range ctx.packageData.Aliases {
			generateAlias(ctx, w, &alias)
		}
	}

	// generate types
	if len(ctx.packageData.Types) > 0 {
		fmt.Fprintf(w, "/* Types */\n\n")

		for _, typ := range ctx.packageData.Types {
			generateType(ctx, w, &typ)
		}
	}

	// generate unions
	if len(ctx.packageData.Unions) > 0 {
		fmt.Fprintf(w, "/* Unions */\n\n")

		for _, union := range ctx.packageData.Unions {
			generateUnion(ctx, w, &union)
		}
	}

	// generate messages
	if len(ctx.packageData.Messages) > 0 {
		fmt.Fprintf(w, "/* Messages */\n\n")

		for _, msg := range ctx.packageData.Messages {
			generateMessage(ctx, w, &msg)
		}

		// generate message registrations
		fmt.Fprintln(w, "func init() {")
		for _, msg := range ctx.packageData.Messages {
			name := camelCaseName(msg.Name)
			fmt.Fprintf(w, "\tapi.RegisterMessage((*%s)(nil), \"%s\")\n", name, ctx.moduleName+"."+name)
		}
		fmt.Fprintln(w, "}")
		fmt.Fprintln(w)

		fmt.Fprintln(w, "var Messages = []api.Message{")
		for _, msg := range ctx.packageData.Messages {
			name := camelCaseName(msg.Name)
			fmt.Fprintf(w, "\t(*%s)(nil),\n", name)
		}
		fmt.Fprintln(w, "}")
	}

	// flush the data:
	if err := w.Flush(); err != nil {
		return fmt.Errorf("flushing data to %s failed: %v", ctx.outputFile, err)
	}

	return nil
}
384912
func (c *Client) RemovePackage(name string) error {
	_, stderr, err := c.execNpm("remove", name)
	if err != nil {
		return errors.New(stderr)
	}
	return nil
}
1121058
func (k *KeyManager) InstallKey(key string) (*KeyResponse, error) {
	return k.InstallKeyWithOptions(key, nil)
}
779180
func RewritePackage(packageName string) {
	pkg, err := packageWithName(packageName)
	if err != nil {
		panic(fmt.Sprintf("unexpected error reading package: '%s'\n%s\n", packageName, err.Error()))
	}

	for _, filename := range findTestsInPackage(pkg) {
		rewriteTestsInFile(filename)
	}
	return
}
1154675
func (c *Client) GetPackage(packageName string) (*Package, error) {
	var resp Package
	req := request{
		method: client.GET,
		url:    makeURL(apiPackages, packageName),
		resp:   &resp,
	}
	if _, err := c.sendRequest(req); err != nil {
		return nil, errors.Newf(err, "failed to get package with name: %s", packageName)
	}
	return &resp, nil
}
1306332
func addPackage(pkgName, typeStr string) string {
	if typeStr == "" {
		return ""
	}

	// we can't use raml package to get basic type and decide whether it is array
	// or not because in this phase the type is already Go type, not RAML type
	switch {
	case strings.HasPrefix(typeStr, "[][]"): // bidimensi array
		return "[][]" + addPackage(pkgName, strings.TrimPrefix(typeStr, "[][]"))
	case strings.HasPrefix(typeStr, "[]"): // array array
		return "[]" + addPackage(pkgName, strings.TrimPrefix(typeStr, "[]"))
	default:
		return aliasPackage(fmt.Sprintf("%v.%v", pkgName, typeStr))
	}
}
1272237
func (p *fileParser) parsePackage(path string) error {
	var pkgs map[string]*ast.Package
	if imp, err := build.Import(path, p.srcDir, build.FindOnly); err != nil {
		return err
	} else if pkgs, err = parser.ParseDir(p.fileSet, imp.Dir, nil, 0); err != nil {
		return err
	}
	for _, pkg := range pkgs {
		file := ast.MergePackageFiles(pkg, ast.FilterFuncDuplicates|ast.FilterUnassociatedComments|ast.FilterImportDuplicates)
		if _, ok := p.importedInterfaces[path]; !ok {
			p.importedInterfaces[path] = make(map[string]*ast.InterfaceType)
		}
		for ni := range iterInterfaces(file) {
			p.importedInterfaces[path][ni.name.Name] = ni.it
		}
		imports, _ := importsOfFile(file)
		for pkgName, pkgPath := range imports {
			if _, ok := p.imports[pkgName]; !ok {
				p.imports[pkgName] = pkgPath
			}
		}
	}
	return nil
}