-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmod.dang
More file actions
101 lines (91 loc) · 3.28 KB
/
Copy pathmod.dang
File metadata and controls
101 lines (91 loc) · 3.28 KB
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
"""
A Dagger module that uses the TypeScript SDK.
"""
type Mod {
"""
Workspace-root-relative path of this module root — the directory holding its
config, and the module's stable identity, independent of where the client is
invoked from. Discovery and generate address the module by this; the files
they read and write live under `sourcePath`.
"""
rootPath: String!
"""
Workspace containing this module.
"""
let ws: Workspace!
"""
Marker filename that skips generate when found at or above this module root.
"""
let skipGenerateFilename: String!
"""
This module root relative to the client's current location: "." when the cwd is
the module itself, "sub/mod" for a module beneath it, ".." for an enclosing one.
A cwd-relative view of rootPath, so listings read the way a shell user would.
"""
path: String! {
let cwd = ws.cwd.trimPrefix("/").trimSuffix("/")
if (rootPath == cwd) {
"."
} else if (cwd == "") {
rootPath
} else if (rootPath.trimPrefix(cwd + "/") != rootPath) {
rootPath.trimPrefix(cwd + "/")
} else if (rootPath == "." or cwd.trimPrefix(rootPath + "/") != cwd) {
let rootDepth = if (rootPath == ".") { 0 } else { rootPath.split("/").length }
cwd.split("/").dropFirst(rootDepth).map { segment => ".." }.join("/")
} else {
rootPath
}
}
"""
Workspace-root-relative path of this module's source directory — where the
TypeScript runtime reads package.json / deno.json and the module's code from.
Usually the module root, but a `source` field in the module config points it
elsewhere: workspace migration writes config to .dagger/modules/<name>/ with
`source` pointing back at the code (e.g. "../../../ci"), so this is resolved
through the engine rather than assumed equal to rootPath.
"""
sourcePath: String! {
let subpath = polyfill.workspace(ws).moduleSource("/" + rootPath).core.sourceSubpath
if (subpath == "" or subpath == ".") { "." } else { subpath }
}
"""
Whether this module or an ancestor contains the configured generate skip marker.
"""
skipGenerate(ws: Workspace!): Boolean! {
hasMarker(ws, skipGenerateFilename)
}
"""
Manage this module's TypeScript SDK build configuration (package.json,
deno.json).
"""
config: ModConfig! {
ModConfig(
sourcePath: sourcePath,
ws: ws,
)
}
"""
Whether this module root or an ancestor contains a marker filename.
"""
let hasMarker(ws: Workspace!, filename: String!): Boolean! {
let markerPath = ws.findUp(name: filename, from: rootPath)
markerPath != null
}
"""
Generate this module's SDK bindings, into its source directory.
Its local dependency closure is staged first so codegen sees up-to-date
bindings for every module it imports. If the generate skip marker is present,
the changeset is empty.
"""
generate(ws: Workspace!): Changeset! {
if (skipGenerate(ws)) {
polyfill.workspace(ws).fork.changes
} else {
# Stage the local dependency closure so this module's codegen sees
# up-to-date dependency bindings before generating it.
let stagedWs = ws.withChanges(polyfill.workspace(ws).moduleSource("/" + rootPath).core.generateLocalDependencies(ws))
polyfill.workspace(stagedWs).moduleSource("/" + rootPath).generate.changes
}
}
}