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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
package inference
import "github.com/vercel/turbo/cli/internal/fs"
// Framework is an identifier for something that we wish to inference against.
type Framework struct {
Slug string
EnvMatcher string
DependencyMatch matcher
}
type matcher struct {
strategy matchStrategy
dependencies []string
}
type matchStrategy int
const (
all matchStrategy = iota + 1
some
)
var _frameworks = []Framework{
{
Slug: "blitzjs",
EnvMatcher: "^NEXT_PUBLIC_",
DependencyMatch: matcher{
strategy: all,
dependencies: []string{"blitz"},
},
},
{
Slug: "nextjs",
EnvMatcher: "^NEXT_PUBLIC_",
DependencyMatch: matcher{
strategy: all,
dependencies: []string{"next"},
},
},
{
Slug: "gatsby",
EnvMatcher: "^GATSBY_",
DependencyMatch: matcher{
strategy: all,
dependencies: []string{"gatsby"},
},
},
{
Slug: "astro",
EnvMatcher: "^PUBLIC_",
DependencyMatch: matcher{
strategy: all,
dependencies: []string{"astro"},
},
},
{
Slug: "solidstart",
EnvMatcher: "^VITE_",
DependencyMatch: matcher{
strategy: all,
dependencies: []string{"solid-js", "solid-start"},
},
},
{
Slug: "vue",
EnvMatcher: "^VUE_APP_",
DependencyMatch: matcher{
strategy: all,
dependencies: []string{"@vue/cli-service"},
},
},
{
Slug: "sveltekit",
EnvMatcher: "^VITE_",
DependencyMatch: matcher{
strategy: all,
dependencies: []string{"@sveltejs/kit"},
},
},
{
Slug: "create-react-app",
EnvMatcher: "^REACT_APP_",
DependencyMatch: matcher{
strategy: some,
dependencies: []string{"react-scripts", "react-dev-utils"},
},
},
{
Slug: "nuxtjs",
EnvMatcher: "^NUXT_ENV_",
DependencyMatch: matcher{
strategy: some,
dependencies: []string{"nuxt", "nuxt-edge", "nuxt3", "nuxt3-edge"},
},
},
{
Slug: "redwoodjs",
EnvMatcher: "^REDWOOD_ENV_",
DependencyMatch: matcher{
strategy: all,
dependencies: []string{"@redwoodjs/core"},
},
},
{
Slug: "vite",
EnvMatcher: "^VITE_",
DependencyMatch: matcher{
strategy: all,
dependencies: []string{"vite"},
},
},
{
Slug: "sanity",
EnvMatcher: "^SANITY_STUDIO_",
DependencyMatch: matcher{
strategy: all,
dependencies: []string{"@sanity/cli"},
},
},
}
func (m matcher) match(pkg *fs.PackageJSON) bool {
deps := pkg.UnresolvedExternalDeps
// only check dependencies if we're in a non-monorepo
if pkg.Workspaces != nil && len(pkg.Workspaces) == 0 {
deps = pkg.Dependencies
}
if m.strategy == all {
for _, dependency := range m.dependencies {
_, exists := deps[dependency]
if !exists {
return false
}
}
return true
}
// m.strategy == some
for _, dependency := range m.dependencies {
_, exists := deps[dependency]
if exists {
return true
}
}
return false
}
func (f Framework) match(pkg *fs.PackageJSON) bool {
return f.DependencyMatch.match(pkg)
}
// InferFramework returns a reference to a matched framework
func InferFramework(pkg *fs.PackageJSON) *Framework {
if pkg == nil {
return nil
}
for _, candidateFramework := range _frameworks {
if candidateFramework.match(pkg) {
return &candidateFramework
}
}
return nil
}
|