-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnpm.go
59 lines (49 loc) · 1.89 KB
/
npm.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package packagemanager
import (
"fmt"
"path/filepath"
"github.com/software-t-rex/packageJson"
)
var nodejsNpm = PackageManager{
Name: "nodejs-npm",
Slug: "npm",
Command: "npm",
Specfile: "package.json",
Lockfile: "package-lock.json",
PackageDir: "node_modules",
ArgSeparator: []string{"--"},
getWorkspaceGlobs: func(rootpath string) ([]string, error) {
pkg, err := packageJson.Read(filepath.Join(rootpath, "package.json"))
if err != nil {
return nil, fmt.Errorf("package.json: %w", err)
}
if len(pkg.Workspaces) == 0 {
return nil, fmt.Errorf("package.json: no workspaces found. packagemanager requires npm workspaces to be defined in the root package.json")
}
return pkg.Workspaces, nil
},
getWorkspaceIgnores: func(pm PackageManager, rootpath string) ([]string, error) {
// Matches upstream values:
// function: https://github.com/npm/map-workspaces/blob/a46503543982cb35f51cc2d6253d4dcc6bca9b32/lib/index.js#L73
// key code: https://github.com/npm/map-workspaces/blob/a46503543982cb35f51cc2d6253d4dcc6bca9b32/lib/index.js#L90-L96
// call site: https://github.com/npm/cli/blob/7a858277171813b37d46a032e49db44c8624f78f/lib/workspaces/get-workspaces.js#L14
return []string{
"**/node_modules/**",
}, nil
},
Matches: func(manager string, version string) (bool, error) {
return manager == "npm", nil
},
detect: func(projectDirectory string, packageManager *PackageManager) (bool, error) {
specfileExists := FileExists(filepath.Join(projectDirectory, packageManager.Specfile))
lockfileExists := FileExists(filepath.Join(projectDirectory, packageManager.Lockfile))
return (specfileExists && lockfileExists), nil
},
canPrune: func(cwd string) (bool, error) {
return true, nil
},
// @FIXME unsuported lockfile
// UnmarshalLockfile: func(contents []byte) (lockfile.Lockfile, error) {
// return lockfile.DecodeNpmLockfile(contents)
// },
}